delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/06/02/12:52:07

From: "S.Turner" <sturner AT notformail DOT nul>
Subject: Re: HELP -- how do I fix this? (thanks for your quick help!)
Newsgroups: comp.os.msdos.djgpp
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1020602081545 DOT 10047G-100000 AT is>
Message-ID: <3cf95a1e$1_4@news.meganetnews.com>
Date: 1 Jun 2002 18:34:54 -0500
Lines: 61
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote:
>
>On 31 May 2002, S.Turner wrote:
>
>> according to RHIDE, the program executes lines of code out of order.
>
>This is normal: the compiler optimizes your code, and as part of this 
>optimization moves code around.  It's a bit confusing at first, but it's 
>not too hard to get used to.

Now that I now that it made things easier.  I was able to 'see' some of
what it was optimizing too.  I went back and cleaned up some code
as well.

>If you want to avoid this reordering, compile without optimizations.  But 
>please be aware that doing so produces code that is very different from 
>optimized code, so you are in fact debugging a different program.  In 
>particular, the bug which causes the crash might not even happen if you 
>compile without optimizations.

I'll leave the optimizations on.  I've heard this enough to believe it!  The
other RHIDE projects I had -didn't- have them on so I turned them on 
to have it match my makefiles now. 

>> The actual crash appears to be coming from a mishandled character array but 
>>I 
>> cannot see how this is happening with this erratic debugging.
>
>You should concentrate on the line that is shown as current when the 
>array is mishandled.  If you cannot figure that out, post here the 
>relevant code fragment and what you see in RHIDE as far as the values of 
>related variables are concerned, and someone will help you.
>
>> The final oddity is that the .EXE file itself when run at the DOS prompt 
>>will 
>> run to  completion without any problems.
>
>This is a sign of using uninitialized memory.  When you run a program 
>under RHIDE, it uses a different memory region, and thus a different 
>random garbage.

Thanks for your help.  I did find the problem. It stems from code like this:

int check_file(char pathname[32]) {
  char *filename;

  if (strrchr(pathname, ':'))
    filename=strrchr(pathname, ':')+1;
  if (strrchr(pathname, '\\'))
    filename=strrchr(pathname, '\\')+1;
.
.
.

This is fine as long as I remember that filename is just a pointer to
pathname plus an offset.  I was manipulating filename and the results
it had on pathname lead to disaster.

Thanks again for you help!
Scott

- Raw text -


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