www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/06/00:45:54

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Seg fault
Date: Fri, 06 Feb 1998 00:31:34 -0500
Organization: Two pounds of chaos and a pinch of salt.
Lines: 46
Message-ID: <34DAA036.3FBA@cs.com>
References: <34DA8954 DOT 320 AT ee DOT net>
NNTP-Posting-Host: ppp219.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

David Mikesell wrote:
> 
> I'm using djgpp 2.01 on dos 6.22 and am trying to work through
> a particularly nasty seg fault bug.  I will purposely keep
> the problem statement general here, but will be happy to
> drill down to the source if nobody can point me in the right
> direction to begin looking.
> 
> I get the seg fault immediately after returning from a function
> that allocates memory...I can't seem to narrow the bug down to
> an offending pointer reference or a free() of a NULL pointer, etc.
> None of the malloc()'s returns a NULL pointer.  Any ideas
> on where to start looking?

Have you checked to see if your function is corrupting the stack?  This
is the most common cause for code that fails to return:  some memory
manipulation inside the function overwrites part of the stack and
damages the stack frame.

Things to look for:
  - use of uninitialized pointers
  - overflowing automatic array bounds
  - calling a memory allocation function with sizeof(<type> *) instead
of sizeof(<type>)
  - inline assembly instructions with improperly matched size suffixes
  - passing buffers to library functions without sufficient space to
store the results
  - use of large automatic arrays that overflow the default 256K stack
for DJGPP programs

There are more possibilities, and these events may not even necessarily
be occurring in the function where the crash happens.  If you can, try
to isolate the code that is crashing and compile it separately, without
the rest of your program.  If it still exhibits improper behavior, then
it is likely to be the cause.  If you can't debug it yourself, post it
here and somebody will try to help.  Please note that we need to see a
_compilable_ fragment of code to guarantee best results, and that it
should be relatively small.  :-)

-- 
---------------------------------------------------------------------
|      John M. Aldrich       | "It may be better to be a live jackal|
|       aka Fighteer I       | than a dead lion, but it is better   |
|   mailto:fighteer AT cs DOT com   | still to be a live lion."            |
| http://www.cs.com/fighteer |                - Lazarus Long        |
---------------------------------------------------------------------

- Raw text -


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