buffer_va_index: use numeric_limits<Id>::max() in max_id() for signed Id types #2290

Merged
leonida/mandy
narekshaghoyandev merged 1 commit from ubiq-buffer-va-index-signed-max-id into main 2026-11-28 18:11:25 +00:00

Pull request successfully merged and closed

narekshaghoyandev commented 2026-11-26 12:50:19 +00:00

Summary

  • Use (std::numeric_limits<Id>::max)() instead of ~Id(0) in BufferVaIndex<Id>::max_id() (runtime/src/buffer_va_index.h).
    • For signed Id types (e.g. int), ~Id(0) evaluates to -1, which causes ranges_.upper_bound({va, max_id()}) in find() to stop before all non-negative IDs at start == va and miss ranges starting at the queried VA.
    • (std::numeric_limits<Id>::max)() works for both signed and unsigned integer Id types (parenthesised to avoid Windows max macro collisions).
  • Add signed_id_cases() regression coverage to runtime/test/buffer_va_index_test.cpp.

Verification

  • g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Wextra -Werror -Wno-mismatched-new-delete -pedantic -O2 -g runtime/test/buffer_va_index_test.cpp — pass (fixed cases, signed ID cases, 200 random tables).
  • g++ -std=c++20 -Wall -Wextra -Werror -Wno-mismatched-new-delete -pedantic -fsanitize=undefined -O2 -g runtime/test/buffer_va_index_test.cpp — pass.
  • Negative control against main: fails (FAIL: signed Id: exact start picks larger positive id, exit 1) before the patch and passes after.
  • python3 -I scripts/check_no_game_data.py runtime/src/buffer_va_index.h runtime/test/buffer_va_index_test.cpp — clean.

Claimed in the coordination issue as: RT-BUFFER-VA-INDEX-SIGNED-MAX-ID (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7192490144)
AI-assisted: yes (Gemini)

## Summary - Use `(std::numeric_limits<Id>::max)()` instead of `~Id(0)` in `BufferVaIndex<Id>::max_id()` (`runtime/src/buffer_va_index.h`). - For signed `Id` types (e.g. `int`), `~Id(0)` evaluates to `-1`, which causes `ranges_.upper_bound({va, max_id()})` in `find()` to stop before all non-negative IDs at `start == va` and miss ranges starting at the queried VA. - `(std::numeric_limits<Id>::max)()` works for both signed and unsigned integer `Id` types (parenthesised to avoid Windows `max` macro collisions). - Add `signed_id_cases()` regression coverage to `runtime/test/buffer_va_index_test.cpp`. ## Verification - `g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Wextra -Werror -Wno-mismatched-new-delete -pedantic -O2 -g runtime/test/buffer_va_index_test.cpp` — pass (fixed cases, signed ID cases, 200 random tables). - `g++ -std=c++20 -Wall -Wextra -Werror -Wno-mismatched-new-delete -pedantic -fsanitize=undefined -O2 -g runtime/test/buffer_va_index_test.cpp` — pass. - Negative control against `main`: fails (`FAIL: signed Id: exact start picks larger positive id`, exit 1) before the patch and passes after. - `python3 -I scripts/check_no_game_data.py runtime/src/buffer_va_index.h runtime/test/buffer_va_index_test.cpp` — clean. Claimed in the coordination issue as: RT-BUFFER-VA-INDEX-SIGNED-MAX-ID (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7192490144) AI-assisted: yes (Gemini)
kawaii-shakal approved these changes 2026-11-26 16:32:46 +00:00
kawaii-shakal left a comment

Reviewed by Claude Code (AI-assisted) on my behalf. Approving.

~Id(0) is -1 for a signed Id, so max_id() was the smallest id rather than the largest.
numeric_limits<Id>::max() is the same value for the unsigned ids in use. Checked: buffer_va_index_test passes
with -fsanitize=address,undefined (g++ 13, Linux). Against main's header, signed_id_cases fails ("exact start
picks larger positive id"), so the test covers the change.


Generated by Claude Code

Reviewed by Claude Code (AI-assisted) on my behalf. Approving. `~Id(0)` is -1 for a signed `Id`, so `max_id()` was the smallest id rather than the largest. `numeric_limits<Id>::max()` is the same value for the unsigned ids in use. Checked: `buffer_va_index_test` passes with `-fsanitize=address,undefined` (g++ 13, Linux). Against main's header, `signed_id_cases` fails ("exact start picks larger positive id"), so the test covers the change. --- _Generated by [Claude Code](https://claude.ai/code)_
zmasi commented 2026-11-28 12:24:21 +00:00

Verified on Windows 11 (10.0.26200.9974) with MSVC 19.44.35228 (x64, /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) against main d48a957bb + 31bd3bd641 (claim #2570#issuecomment-7239117859):

  • Line-by-line diff audit: Clean (runtime/src/buffer_va_index.h, runtime/test/buffer_va_index_test.cpp); replaces ~Id(0) with parenthesized (std::numeric_limits<Id>::max)() in BufferVaIndex::max_id() so starts_.upper_bound({va, max_id()}) works for signed integer Id instantiations instead of comparing against -1. check_no_game_data.py clean.
  • Red (d48a957bb + PR test): buffer_va_index_test.exe fails (rc=1, FAIL: signed Id: exact start picks larger positive id).
  • Green (d48a957bb + 31bd3bd641 merge): Auto-merges cleanly (rc=0), compiles with 0 warnings under /W4 /permissive-, and passes (BufferVaIndex: fixed cases and 200 random tables agree with the scan, rc=0).

AI-assisted.

Verified on Windows 11 (`10.0.26200.9974`) with MSVC `19.44.35228` (`x64`, `/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2`) against `main` `d48a957bb` + `31bd3bd641` (claim `#2570#issuecomment-7239117859`): - **Line-by-line diff audit**: Clean (`runtime/src/buffer_va_index.h`, `runtime/test/buffer_va_index_test.cpp`); replaces `~Id(0)` with parenthesized `(std::numeric_limits<Id>::max)()` in `BufferVaIndex::max_id()` so `starts_.upper_bound({va, max_id()})` works for signed integer `Id` instantiations instead of comparing against `-1`. `check_no_game_data.py` clean. - **Red (`d48a957bb` + PR test)**: `buffer_va_index_test.exe` fails (`rc=1`, `FAIL: signed Id: exact start picks larger positive id`). - **Green (`d48a957bb` + `31bd3bd641` merge)**: Auto-merges cleanly (`rc=0`), compiles with `0` warnings under `/W4 /permissive-`, and passes (`BufferVaIndex: fixed cases and 200 random tables agree with the scan`, `rc=0`). AI-assisted.
MoonEyes commented 2026-11-28 18:11:22 +00:00

Red/green: On main buffer_va_index_test fails 1 check (with a signed Id an exact start picks the wrong id because max_id() returns -1), and with the PR ctest -R "^buffer_va_index$" passes.
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.

Red/green: On main buffer_va_index_test fails 1 check (with a signed Id an exact start picks the wrong id because max_id() returns -1), and with the PR ctest -R "^buffer_va_index$" passes. Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
OreoFR commented 2026-11-28 22:01:00 +00:00

Verified by OreoFR

  • Base: main c1ecf04ed + PR head 31bd3bd64; green run in a merge package of 16 PRs, no new ctest failure vs main
  • Test: ctest -R "^buffer_va_index$"
  • Red on main: 1 failure (signed id: an exact start takes the largest positive id)
  • Green with the PR: OK
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

**Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `31bd3bd64`; green run in a merge package of 16 PRs, no new ctest failure vs main - Test: `ctest -R "^buffer_va_index$"` - Red on main: 1 failure (signed id: an exact start takes the largest positive id) - Green with the PR: OK - Verdict: READY - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No description provided.