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 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 CString.
Delete_CString() CStrings are allocated ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access