[ee122] Segfault Madness (need expert)

Daniel Killebrew dank at eecs.berkeley.edu
Wed Oct 31 15:36:19 PDT 2007


I don't know if theres an equivalent to this in UNIX, but when I'm 
writing windows code, theres some special memory debugging flags that 
you can set.
_CrtSetDbgFlag
Then the c runtime library can do various useful things for you, such as 
putting boundaries around allocated memory, and checking that you 
haven't written outside your allocated memory whenever you (de)allocate. 
It can do some other nice things as well.

Daniel

vern at EECS.Berkeley.EDU wrote:
> Yes, this (unfortunately) is a classic C pointer error, where memory is
> getting overwritten and the problem only manifests later when the trashed
> value is accessed.  In Drew's code, adding the new variable changes the
> stack layout.  This suggests (but not definitively) that in this case the
> problem is something being overrun on the stack due to a local buffer,
> rather than a heap pointer managed by malloc/free.
>
> One way to try to find problems like this is to use gcc -g -Wall in order
> to catch problems that can be found at compile time, and then to execute
> inside of gdb, which will at least show the location of where the problem
> *manifests* (-g turns on debugging symbols).
>
> I believe the instructional machines also have some more powerful tools
> available such as Purify or Coverity.  But these will have a learning curve
> associated with figuring out how to use them.
>
> 		Vern
> _______________________________________________
> ee122 mailing list
> ee122 at mailman.ICSI.Berkeley.EDU
> http://mailman.ICSI.Berkeley.EDU/mailman/listinfo/ee122
>
>   


More information about the ee122 mailing list