Bounded C line-reader lab
Download the lab archive, extract c-input-contracts, and read README.md and reader.h. Use an eight-bit-byte C11 target with Clang or GCC. Windows learners can use WSL for the documented shell commands. Implementation and retained evidence occupy 8–12 hours inside the 18–26-hour replacement package.
Contract before code
The reader borrows a writable buffer and source context. The byte source returns 0–255, end (-1), or error (-2). main.c supplies a stdio adapter; tests supply an in-memory source with injected errors. No heap allocation is needed.
Capacity includes the trailing zero byte. A blank line succeeds; end before any content returns EOF. A nonempty final line without newline may succeed. Overlong and NUL-containing lines drain through newline/end and clear the first output byte. Input errors stop immediately and override those rejection statuses. Other output bytes after rejection are unspecified. Zero capacity and null function/buffer return BAD_ARGUMENT without reading or writing. Valid pointer/storage and source behavior remain caller obligations.
Implement and verify
Copy starter.c to solution.c. Predict boundary cases before implementing. From the extracted directory:
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 check-sanitized
./check-sanitized
cc -std=c11 -Wall -Wextra -Wpedantic solution.c main.c -o reader
printf 'hi\nabcdefgh\nq\n' | ./reader
The CLI prints OK:hi, REJECT:LONG, then OK:q, on separate lines. Use the reference only after an attempt. Do not compile every source file together: choose exactly one implementation and one entry point. Do not disable assertions. Keep unsupported sanitizer runs marked unsupported and obtain evidence on a supported host before claiming the instrumentation gate.
Evidence
After this packet, reuse the reader in the semester's runnable safety workshop. It adds an exact-allocation fuzz adapter, a real sanitizer failure and repair, and comparison with safe Rust. Its time belongs to the existing semester strand, not an extra Module 1 assignment. Keep this lab's callback-error tests: byte-only fuzz inputs cannot represent an I/O failure by themselves.
Retain compiler/target/flags, predictions, one failing and repaired regression, test output, a source-position trace, and an assistance declaration. Add a fresh capacity/input-error case. Explain why this bounded-storage design can still spend unbounded time draining an endless line. Pass CI1–CI6 and reuse the packet in the semester project.