szn

Bug 394 — Width-table / Thai / clock robustness cluster

394. Four robustness findings

Severity: LOW Status: ✅ RESOLVED

Fix (applied)

| Item | Change | |——|——–| | clock.zig | New utcHms(secs) clamps negative epoch seconds to 0 before the u64 cast; renderClock uses it. Test covers -100 and a known timestamp. | | thai.zig | Negative libthai break positions are skipped instead of panicking on the usize cast. | | char_width.zig | applyCodepointWidths now validates the whole list first (inverted ranges rejected with InvalidEntry) and only then clears + applies, so a bad config leaves the previous table intact instead of half-applying. Capacity pre-check prevents mid-apply saturation. |

Remaining

The module-level mutable tables (char_width.overrides, thai.libthai_*) still violate AGENTS.md rule 4; removing them is an architectural change (dependency-injected width context) deferred to a dedicated refactor.

# Site Finding
a char_width.zig:30-31, thai.zig:436-437 Module-level mutable state (override_count/overrides table; lazy libthai_instance/libthai_tried) with no locking — violates AGENTS.md rule 4 (“No global state”).
b char_width.zig:70-89 applyCodepointWidths clears the table then applies entries one-by-one; an invalid entry mid-list returns an error leaving earlier entries active (half-applied config). Also no start <= end validation — inverted ranges silently match nothing.
c thai.zig:554 @intCast(breaks_buf[i]) (c_int → usize) panics on a negative position; only the upper bound is checked at :555. Guard >= 0.
d clock.zig:63 UTC branch does @as(u64, @intCast(now_secs)) — panics if time() returns negative (dead RTC / skewed VM). Localtime branch handles negatives fine.