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

Open
opened 2026-11-26 21:20:43 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2290
Author: @narekshaghoyandev
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: ubiq-buffer-va-index-signed-max-id


📝 Commits (1)

  • 31bd3bd buffer_va_index: use numeric_limits::max() in max_id() for signed Id types

📊 Changes

2 files changed (+14 additions, -1 deletions)

View changed files

📝 runtime/src/buffer_va_index.h (+2 -1)
📝 runtime/test/buffer_va_index_test.cpp (+12 -0)

📄 Description

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)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2290 **Author:** [@narekshaghoyandev](https://github.com/narekshaghoyandev) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `ubiq-buffer-va-index-signed-max-id` --- ### 📝 Commits (1) - [`31bd3bd`](https://github.com/ubiquitarianism/leonida/commit/31bd3bd641ed2dc35c83e958a466255fa9c0a883) buffer_va_index: use numeric_limits<Id>::max() in max_id() for signed Id types ### 📊 Changes **2 files changed** (+14 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/buffer_va_index.h` (+2 -1) 📝 `runtime/test/buffer_va_index_test.cpp` (+12 -0) </details> ### 📄 Description ## 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#2294
No description provided.