Decide and write down the libakstdlib wrapper adoption rule #19

Open
opened 2026-08-02 18:32:59 -04:00 by tachikoma · 0 comments
Collaborator

Source: TODO.md, "libakstdlib wrappers not yet adopted" (at bbb7b8f)

libakgl links libakstdlib and uses ten of its wrappers. It calls the raw libc
function at a good many more sites.

The four that were carrying a real defect are adopted, for the record:
aksl_fclose (an unchecked close in akgl_game_save lost buffered data
silently), aksl_fgetc (fgetc(3) spells EOF and a read error the same way),
aksl_snprintf at two sites that were truncating under a silenced
-Wformat-truncation, and aksl_strncpy at the two src/game.c sites the
fixed-width copy sweep missed.

What is left is the pure-arithmetic wrappers, deliberately not adopted:

Function Raw sites
memset 38
strlen 14
strcmp 9
strncmp 9
memcpy 6
memcmp 2

Every one of these can only fail on a NULL argument, and at all but a handful of
those sites the argument is a stack object whose address cannot be NULL.
aksl_memset and aksl_memcpy are used twice each, which is the inconsistency
worth naming: there is no rule distinguishing those two sites from the other 44.

Converting them costs an errctx check per line and buys a NULL check the
compiler already knows is redundant. Not converting them leaves the file mixing
two spellings of the same operation.

Pick one and write it down. The recommendation on record is to convert only
where the argument is a parameter or a heap pointer, and say so in AGENTS.md,
rather than either extreme.

Files: AGENTS.md, src/ throughout


Filed by Tachikoma (Claude Code, Opus 5, 1M context)

**Source:** TODO.md, "libakstdlib wrappers not yet adopted" (at bbb7b8f) `libakgl` links `libakstdlib` and uses ten of its wrappers. It calls the raw libc function at a good many more sites. The four that were carrying a real defect are adopted, for the record: `aksl_fclose` (an unchecked close in `akgl_game_save` lost buffered data silently), `aksl_fgetc` (`fgetc(3)` spells EOF and a read error the same way), `aksl_snprintf` at two sites that were truncating under a silenced `-Wformat-truncation`, and `aksl_strncpy` at the two `src/game.c` sites the fixed-width copy sweep missed. What is left is the pure-arithmetic wrappers, deliberately not adopted: | Function | Raw sites | |---|---:| | `memset` | 38 | | `strlen` | 14 | | `strcmp` | 9 | | `strncmp` | 9 | | `memcpy` | 6 | | `memcmp` | 2 | Every one of these can only fail on a NULL argument, and at all but a handful of those sites the argument is a stack object whose address cannot be NULL. `aksl_memset` and `aksl_memcpy` are used twice each, **which is the inconsistency worth naming: there is no rule distinguishing those two sites from the other 44.** Converting them costs an `errctx` check per line and buys a NULL check the compiler already knows is redundant. Not converting them leaves the file mixing two spellings of the same operation. **Pick one and write it down.** The recommendation on record is to convert only where the argument is a parameter or a heap pointer, and say so in `AGENTS.md`, rather than either extreme. **Files:** `AGENTS.md`, `src/` throughout --- Filed by Tachikoma (Claude Code, Opus 5, 1M context)
tachikoma added this to the 0.9.x milestone 2026-08-02 18:32:59 -04:00
tachikoma added the docsdesign-decisionblast-radius:low labels 2026-08-02 18:32:59 -04:00
tachikoma added the status::grooming label 2026-08-02 18:49:14 -04:00
Sign in to join this conversation.