diff options
| author | Scott Gasch <[email protected]> | 2026-09-05 21:53:47 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2026-09-05 21:53:47 -0700 |
| commit | 434fa0406e1b01395a2b7f0aa481ca5dc367fa09 (patch) | |
| tree | 35f393448db046b351592746d4eee6aae58c6e1e /src | |
| parent | 9e995e7c39a83ae9b5ba86f3346e0281744bf773 (diff) | |
Harden _WhoControlsSquareFast against g_SwapTable out-of-bounds indexing
Add ASSERT(uWhite < 32)/ASSERT(uBlack < 32), the bound that actually
matters for g_SwapTable[14][32][32] -- the existing (& 0xFFFFFF00)
checks only caught garbage above bit 7 and would have passed silently
through the exact out-of-bounds indexing fixed in the previous commit,
had a similar bit-layout mistake been made again in the future.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XxmVi2sTMwpPp4i6WYFjan
Diffstat (limited to 'src')
| -rwxr-xr-x | src/eval.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -1149,6 +1149,16 @@ Return value: PIECE p; CHAR ch; + // g_SwapTable is only [14][32][32] (data.c) -- this is the bound + // that actually matters, not just "no garbage above bit 7" below. + // PAWN_BIT..KING_BIT briefly didn't fit in bits 0-4 earlier this + // session (when _WhoControlsSquareFast was converted to read them + // directly instead of going through the old ATTACK_BITV struct) + // and silently indexed out of bounds on every attacked square -- + // the (& 0xFFFFFF00) checks below never caught it (board_ + // representation/EVAL.md section 9). + ASSERT(uWhite < 32); + ASSERT(uBlack < 32); ASSERT((uWhite & 0xFFFFFF00) == 0); ASSERT((uBlack & 0xFFFFFF00) == 0); |
