delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/12/07:14:25

Date: Mon, 12 Jul 1999 13:10:09 +0200
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Message-Id: <199907121110.NAA07043@acp3bf.physik.rwth-aachen.de>
To: daphire AT aol DOT com (Da Phire)
Cc: djgpp AT delorie DOT com
Subject: Re: Wierd Memory Problems
Newsgroups: comp.os.msdos.djgpp
Organization: RWTH Aachen, III. physikalisches Institut B
X-Newsreader: TIN [version 1.2 PL2]
Reply-To: djgpp AT delorie DOT com

In article <19990711224517 DOT 20554 DOT 00004047 AT ng-ff1 DOT aol DOT com> you wrote:

[...]
> declared and initialized properly, and I found that changing the
> order in which the variables were declared would sometimes help (the
> error I would get is SIGSEGV, which I know is a memory-related
> error). 
[...]

This behaviour change on shuffling the order of variable declarations
is a 95% certain sign of exactly one type of error: buffer overrun.

You're writing past the end (or before the beginning) of some array
variable. This ends up overwriting the contents of some *other*
variable. Reordering the variables will change which variable's value
will be garbled, and thus change behaviour from one SIGSEGV to
another, or (worse) to a silent miscalculation of results.

Examine all your variables' values carefully while running the program
in a debugger. Special attention should be paid to every kind of array
index: is it inside the bounds of that array?

For heavy-duty work of this kind, a checking tool like 'Purify' or
'Checker-gcc' would be needed. I have Checker-gcc running on Linux,
and it's really nice.  Unfortunately, I don't think it is available
for DJGPP, yet.

BTW: It'd have been more useful to post a minimized, but still compilable
example source code, instead of this very verbose description.


--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


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