[PR #923] [MERGED] arena_size: a negative LEONIDA_ARENA_MB clamps to the 16 MiB floor, not the 4095 MiB maximum (ARENA-NEGATIVE-MB) #961

Closed
opened 2026-11-26 20:19:37 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/923
Author: @TuroYT
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @QemmHD

Base: main ← Head: fix/arena-negative-mb


📝 Commits (1)

  • 49e6392 arena_size: parse LEONIDA_ARENA_MB as signed so negatives hit the floor (ARENA-NEGATIVE-MB)

📊 Changes

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

View changed files

📝 runtime/src/arena_size.h (+4 -1)
📝 runtime/test/arena_size_test.cpp (+3 -0)

📄 Description

Claimed in the coordination issue as: ARENA-NEGATIVE-MB (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135560869)

What was wrong

runtime/src/arena_size.h:63 parsed LEONIDA_ARENA_MB with std::strtoull. A negative number wraps to a huge
unsigned value, so std::clamp returned the 4095 MiB maximum. The header comment documents a clamp to 16..4095 MiB,
and a negative number should reach the 16 MiB floor.

Reproduction on origin/main (g++ 16, -std=c++20 -fsanitize=address,undefined, a probe calling
decide_arena_size with an empty ArenaLimits):

[-5] -> 4095 MiB
[-1] -> 4095 MiB
[-0] -> 16 MiB
[ -5] -> 4095 MiB
[-99999999999999999999] -> 4095 MiB
[99999999999999999999] -> 4095 MiB
[abc] -> 16 MiB
[+20] -> 20 MiB
[0x20] -> 16 MiB
[99999] -> 4095 MiB

What changed

  • runtime/src/arena_size.h: parse with std::strtoll and clamp as a signed value before converting to
    VkDeviceSize. Negative text now reaches the 16 MiB floor. Every other input keeps its result.
  • runtime/test/arena_size_test.cpp: three new checks in request_without_limits: "-5" gives 16 MiB,
    "-99999999999999999999" gives 16 MiB, "99999999999999999999" gives 4095 MiB.

Tested

  • g++ -std=c++20 -Wall -Wextra -fsanitize=address,undefined -I runtime/src -I <dir with vulkan/ and vk_video/> runtime/test/arena_size_test.cpp then run the binary: builds with no warnings, prints the summary line, exit 0.
  • Same command with clang++: exit 0. It prints three -Wmissing-field-initializers warnings from
    query_arena_limits (lines 34 to 36), which this change does not touch.
  • Same test built against the origin/main header: fails with line 32: decide_arena_size("-5", none).bytes == 16 * MiB, exit 1.
  • The probe above on the fixed header: -5, -1, -0, -5, -99999999999999999999 and abc give 16 MiB;
    99999999999999999999 and 99999 give 4095 MiB; +20 gives 20 MiB; 0x20 gives 16 MiB.
  • python3 -I scripts/check_no_game_data.py runtime/src/arena_size.h runtime/test/arena_size_test.cpp: exit 0.
  • git diff --check: clean.

Not tested

  • The Windows build and the CTest registration of arena_size on Windows.
  • ctest on Linux for the whole runtime tree (only the single test file was built and run).
  • A GPU run, and the real environment path through runtime/shims/d3d12_vulkan_device.cpp.
  • The new checks against the origin/main header ran one at a time through the probe. The test stops at its first
    failing check (line 32), so the huge-negative check was not reached by the test binary on the unfixed header.

AI-assisted (Claude Code).


🔄 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/923 **Author:** [@TuroYT](https://github.com/TuroYT) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `fix/arena-negative-mb` --- ### 📝 Commits (1) - [`49e6392`](https://github.com/ubiquitarianism/leonida/commit/49e6392c9e6ee45cfce8ef7b690aaa7fc223ce0d) arena_size: parse LEONIDA_ARENA_MB as signed so negatives hit the floor (ARENA-NEGATIVE-MB) ### 📊 Changes **2 files changed** (+7 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/arena_size.h` (+4 -1) 📝 `runtime/test/arena_size_test.cpp` (+3 -0) </details> ### 📄 Description Claimed in the coordination issue as: ARENA-NEGATIVE-MB (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135560869) ## What was wrong `runtime/src/arena_size.h:63` parsed `LEONIDA_ARENA_MB` with `std::strtoull`. A negative number wraps to a huge unsigned value, so `std::clamp` returned the 4095 MiB maximum. The header comment documents a clamp to 16..4095 MiB, and a negative number should reach the 16 MiB floor. Reproduction on `origin/main` (g++ 16, `-std=c++20 -fsanitize=address,undefined`, a probe calling `decide_arena_size` with an empty `ArenaLimits`): ``` [-5] -> 4095 MiB [-1] -> 4095 MiB [-0] -> 16 MiB [ -5] -> 4095 MiB [-99999999999999999999] -> 4095 MiB [99999999999999999999] -> 4095 MiB [abc] -> 16 MiB [+20] -> 20 MiB [0x20] -> 16 MiB [99999] -> 4095 MiB ``` ## What changed - `runtime/src/arena_size.h`: parse with `std::strtoll` and clamp as a signed value before converting to `VkDeviceSize`. Negative text now reaches the 16 MiB floor. Every other input keeps its result. - `runtime/test/arena_size_test.cpp`: three new checks in `request_without_limits`: `"-5"` gives 16 MiB, `"-99999999999999999999"` gives 16 MiB, `"99999999999999999999"` gives 4095 MiB. ## Tested - `g++ -std=c++20 -Wall -Wextra -fsanitize=address,undefined -I runtime/src -I <dir with vulkan/ and vk_video/> runtime/test/arena_size_test.cpp` then run the binary: builds with no warnings, prints the summary line, exit 0. - Same command with `clang++`: exit 0. It prints three `-Wmissing-field-initializers` warnings from `query_arena_limits` (lines 34 to 36), which this change does not touch. - Same test built against the `origin/main` header: fails with `line 32: decide_arena_size("-5", none).bytes == 16 * MiB`, exit 1. - The probe above on the fixed header: `-5`, `-1`, `-0`, ` -5`, `-99999999999999999999` and `abc` give 16 MiB; `99999999999999999999` and `99999` give 4095 MiB; `+20` gives 20 MiB; `0x20` gives 16 MiB. - `python3 -I scripts/check_no_game_data.py runtime/src/arena_size.h runtime/test/arena_size_test.cpp`: exit 0. - `git diff --check`: clean. ## Not tested - The Windows build and the CTest registration of `arena_size` on Windows. - `ctest` on Linux for the whole runtime tree (only the single test file was built and run). - A GPU run, and the real environment path through `runtime/shims/d3d12_vulkan_device.cpp`. - The new checks against the `origin/main` header ran one at a time through the probe. The test stops at its first failing check (line 32), so the huge-negative check was not reached by the test binary on the unfixed header. AI-assisted (Claude Code). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:37 +01:00
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#961
No description provided.