Unit 03 of 03
Robustness
Why undefined behavior exists and how its defined counterpart is written instead, reporting errors with return codes and error numbers, bounds checking where the caller supplies the length, and isolating implementation-defined behavior from portable code.
Published Updated
Lessons
- 01 Undefined Behavior Reading a dangling pointer, using freed memory, freeing a block twice, and accessing an array out of bounds are all undefined behavior; none of them run — the lesson describes each one in prose and runs its defined counterpart alongside it. 14 min read
- 02 Error Handling Patterns When a function fails, who frees the block it had already allocated up to that point is not a rule the compiler enforces — it is the function's own contract; the lesson measures this by running a return code, an error number, and a single-exit-point cleanup pattern. 13 min read
- 03 Bounds Checking record_create's limit parameter takes its length not from the source but from the caller; the lesson runs how this parameter prevents a buffer overflow, snprintf's truncation notification, and whose responsibility the length is. 13 min read
- 04 Portability Three values the shared core deliberately never printed — addresses, type sizes other than char, malloc(0)'s return — are target-dependent; this lesson isolates target-dependent behavior by printing a comparison the standard guarantees instead of a value, and gathers the course's fifteen lessons into a closing table. 11 min read