Skip to main content

Input boundary prediction practice

Predict first, then compare the calibration.

  1. Capacity 1: distinguish empty input from a single newline.
  2. Capacity 4: compare abc plus newline with abcd plus newline.
  3. Capacity 2: an overlong line is followed by q plus newline. What must the next call return?
  4. A source delivers byte 255 then end. Why must the source result stay in int?
  5. A line contains NUL, then the source fails. Which status wins?
  6. Why might a reader that returns early on an overlong line pass a sanitizer check?

Calibration​

  1. EOF versus OK with an empty terminated string.
  2. OK with abc versus LONG; both consume the delimiter.
  3. OK with q, because rejected input was drained.
  4. A byte must remain distinguishable from a negative end sentinel. Narrowing first can destroy that distinction.
  5. IO_ERROR; the reader clears buf[0] and returns immediately.
  6. It may access only valid storage while violating the source-position contract. Assertions on consecutive calls detect that logical error.

Repeat after a delay with a changed capacity and an unterminated final line. Do not treat recalled answers as independent transfer.