[ee122] Segfault Madness (need expert)

vern at cs.berkeley.edu vern at cs.berkeley.edu
Wed Oct 31 15:08:24 PDT 2007


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


More information about the ee122 mailing list