Growable C buffer with fault injection
Download the lab archive. Extract c-buffer-contracts, read buffer.h and README.md, and copy starter.c to solution.c. Use C11 and Clang/GCC. The extension replaces the earlier short lab; implementation and evidence take 9–14 hours within its 20–30-hour package.
Implement the contract
Implement the pure planner, reserve, push and destroy. length counts initialized elements; capacity counts allocated slots. Failed growth preserves the complete prior state. A no-op reserve does not allocate. Destroy frees the allocation, resets pointer/length/capacity, and is safe to repeat on this initialized owner. The owner may then be reused with its still-live allocator context.
Do not shallow-copy an owner, evaluate stale element pointers after growth, or pass invalid callbacks/storage. The reference chooses allocate-copy-release; its allocator must return distinct live storage with suitable alignment or NULL on failure. The planner must leave its output untouched on rejection and avoid overflowing arithmetic.
cc -std=c11 -Wall -Wextra -Wpedantic -Werror solution.c check.c -o check
./check
cc -std=c11 -Wall -Wextra -Wpedantic -g -O1 -fsanitize=address,undefined -fno-sanitize-recover=all solution.c check.c -o checked
./checked
Select one implementation, retain assertions, and use a supported instrumentation host. Inspect reference.c after your own attempt. The tests enumerate 5,508 small planner cases, exercise near-limit arithmetic without huge allocations, fault successive growth requests, check existing values after failure/retry, and account for live allocations through cleanup and reuse.
Evidence packet
Connect the ownership trace to the semester's runnable safety workshop. Its Vec exercise rejects a reference used across mutation and verifies two repairs. Reacquiring through a valid logical index explains the connection to this buffer's growth rule; it does not prove arbitrary indices remain valid after deletion or reordering. The workshop reuses the existing strand budget.
Keep a before/after ownership diagram, one failing and repaired regression, a fresh failure schedule, compiler/flags and diagnostic output, and your source/assistance record. Preserve an index across growth and reacquire its element. Explain why memory use peaks during allocate-copy-release. Pass MP1–MP6; reuse the packet in the existing semester project.