Land a character written past a short row's terminator

A grid row is a NUL-terminated string, and `putchar_at()` wrote the character,
advanced and terminated -- so `CHAR 1, 40, 1, "#"` on an otherwise empty row
stored the `#` at column 40 with `text[1][0]` still `'\0'`, and the render loop,
which stops at the terminator, drew nothing at all.

The silent nothing is the trap. The write succeeded, the cursor moved, the
stdout mirror showed the character, and only the window stayed blank -- so the
program looked right everywhere except where it mattered. The documented
truncation on the way *back* is fine and is unaffected.

`putchar_at()` now fills the gap with spaces before storing.

**Padded there rather than in `sink_moveto()`**, which TODO.md proposed: this way
`moveto` stays read-only -- the objection that entry raised against its own
suggestion -- and a row is only ever padded when a character actually arrives.

The pad fills from the terminator rather than replacing it. The buffer is not
cleared between rows, so replacing only the terminator would expose the tail of
whatever longer row used to be there: writing "ABCDEFGHIJ", truncating it to
"ABCX", then writing at column 7 must give "ABCX   Z" and not "ABCX FGZ".
tests/akgl_backends.c asserts all three cases, and the middle one keeps the
truncation pinned.

TODO.md section 6 item 32, struck.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-02 00:13:42 -04:00
parent 8594d8471d
commit a1dcfcacf3
5 changed files with 89 additions and 7 deletions

16
TODO.md
View File

@@ -1982,8 +1982,20 @@ in either corpus runs for minutes, which is why the first of these had never bee
in `examples/breakout/characters` does, and it is the one thing in that listing that will break
on a different font or window. Two more `RGR()` indices would answer it.
32. **A character written past a short row's terminator is stored where nothing will render
it.** A grid row is a NUL-terminated string and `putchar_at()` (`src/sink_akgl.c:89`)
32. ~~**A character written past a short row's terminator is stored where nothing will
render it.**~~ **Done** -- `putchar_at()` (`src/sink_akgl.c`) fills the gap with spaces
before storing, so a positioned write always lands.
**Padded in `putchar_at()` rather than in `sink_moveto()`**, which is the friendlier of
the two options this entry offered and avoids its own objection: `moveto` stays
read-only, and a row is only ever padded when a character actually arrives. The pad
fills from the terminator rather than replacing it, because the buffer is not cleared
between rows -- replacing only the terminator would expose the tail of whatever longer
row used to be there, and `tests/akgl_backends.c` asserts exactly that case.
The documented truncation on the way back is unaffected and is asserted beside it.
The original report: A grid row is a NUL-terminated string and `putchar_at()` (`src/sink_akgl.c:89`)
writes the character, advances, and terminates -- so `CHAR 1, 40, 1, "#"` on an empty row
stores `#` at column 40 with `text[1][0]` still `'\0'`, and `sink_akgl_render()` draws
nothing at all. The same call on a row already 50 characters long draws the `#` and erases