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

Merged
narekshaghoyandev merged 1 commit from upstream-pr/2290 into main 2026-11-28 18:11:25 +00:00
narekshaghoyandev commented 2026-11-26 12:50:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by narekshaghoyandev on 2026-11-26T12:50:19Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5510332437 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2290). Originally posted by [narekshaghoyandev](https://github.com/narekshaghoyandev) on 2026-11-26T12:50:19Z. --- ## 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 commented 2026-11-26 16:32:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-26T16:32:46Z.

Review: APPROVED


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

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6077608235 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2290#pullrequestreview-6077608235). Originally posted by [kawaii-shakal](https://github.com/kawaii-shakal) on 2026-11-26T16:32:46Z. **Review:** APPROVED --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T12:24:21Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239204600 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2290#issuecomment-7239204600). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T12:24:21Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T18:11:22Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7243598814 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2290#issuecomment-7243598814). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T18:11:22Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:01:00Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246435861 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2290#issuecomment-7246435861). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T22:01:00Z. --- **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 reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2290
No description provided.