Skip to main content

Checkpoint: Trust Nothing on Disk

intermediate28 min readLesson 132 of 148

Prove the robust reader: valid data in, garbage rejected, no crash on any input.

The task

Implement db_load (see the challenge). This is the module's contract made executable: the happy path is easy, but the graded cases are the truncated file, the wrong magic, the missing file, and the NULL arguments. A reader that returns sane errors instead of crashing is the difference between a tool and a liability.

Passing this proves you can read untrusted bytes the way production code must: bounds-checked, error-valued, allocation-free.

Next module: return codes, errno, and APIs designed so failure is impossible to ignore.