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
typedefed 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
CStrings are allocated on the ...