Extended Example
In this section we present a detailed example of debugging seg faults.
Below is some C code that might be part of an implementation of a managed string type similar to C++ strings. The code, contained in the source file cstring.c, implements a type called CString
; however, it's riddled with bugs, obvious and subtle. Our goal is to find all these bugs and correct them.
CString
is a typede
fed alias for a structure containing a pointer to storage for a char
string together with a variable that stores the string's length. Some utility functions useful for string handling have been implemented:
Init_CString()
Takes an old-style C string as an argument and uses it to initialize a new CString
.
Delete_CString()
CStrings
are allocated ...
Get The Art of Debugging with GDB, DDD, and Eclipse now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.