delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/16/01:02:25

From: "John M. Aldrich" <fighteer AT NO DOT SPAM DOT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: FOUND DJP BUG.
Date: Tue, 15 Apr 1997 07:05:59 -0700
Organization: Two pounds of chaos and a pinch of salt
Lines: 56
Message-ID: <33538B47.7DA3@NO.SPAM.cs.com>
References: <3353E3F7 DOT 6369 AT tc DOT umn DOT edu>
NNTP-Posting-Host: ppp108.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jawed Karim wrote:
> 
> /*
> compile the following code with DJGPP and run it. Observe the output.
> Then, run DJP on the executable and run it again. The output differs! I
> think that qualifies as a bug, because compressed EXE's should not
> behave any differently than uncompressed EXE's.
> */

No, this is quite simply a major bug in your program.  Allow me to
explain, but first let me ask you where in the nine hells you learned
C?  And who taught you to be so "polite"?  Oh, well... here goes:

> #include <stdio.h>
> 
> void main(void)

This is a nono.  main() must return an integer value to the operating
system - this forms the return code of the program!  Don't leave it out,
despite what many C books tell you.  They are WRONG.

> {
>         char *string = NULL;
> 
>         if (*string != NULL)

This will never work as intended, because you're dereferencing 'string'
before comparing it to NULL.  Try just "if ( string != NULL )" here. 
This should have caused a segmentation violation when you ran the
program, unless you tried it under Windows.  In DOS, all you'd get is a
crash.

>                 printf("\n%s\n", string);
> }

BTW, the reason for the different behavior with djp is that the data at
the virtual address '0x0' is probably part of the program's executable
code, or some internal structure of the program, and thus differs when
the executable itself is different.

I'm surprised that this program worked at all, and didn't cause all
sorts of nasty crashes.

-- 
John M. Aldrich <fighteer AT cs DOT com>                      

* Anything that happens, happens.
* Anything that, in happening, causes something else to happen,
  causes something else to happen.
* Anything that, in happening, causes itself to happen again, happens
  again.
* It doesn't necessarily do it in chronological order, though.
 
                                       --- Douglas Adams


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019