From 49e6392c9e6ee45cfce8ef7b690aaa7fc223ce0d Mon Sep 17 00:00:00 2001 From: Romain PINSOLLE Date: Tue, 24 Nov 2026 16:11:47 +0100 Subject: [PATCH] arena_size: parse LEONIDA_ARENA_MB as signed so negatives hit the floor (ARENA-NEGATIVE-MB) strtoull("-5") wraps to 2^64-5, so decide_arena_size clamped it to the 4095 MiB maximum. strtoll clamps "-5" and "-99999999999999999999" to the 16 MiB floor, as the header comment documents. Adds checks for "-5", the huge negative and the huge positive to arena_size_test. Other inputs keep their results. --- runtime/src/arena_size.h | 5 ++++- runtime/test/arena_size_test.cpp | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/runtime/src/arena_size.h b/runtime/src/arena_size.h index 8f4ca4cafb..196b03e3ee 100644 --- a/runtime/src/arena_size.h +++ b/runtime/src/arena_size.h @@ -60,7 +60,10 @@ struct ArenaSize { // invalid Vulkan, while one under 16 MiB is only small (and no conformant device reports under 1 GiB). inline ArenaSize decide_arena_size(const char* env, const ArenaLimits& limits, VkDeviceSize allocation_overhead = 0) { VkDeviceSize megabytes = kArenaDefaultMiB; - if (env && *env) megabytes = std::clamp(std::strtoull(env, nullptr, 10), kArenaMinMiB, kArenaMaxMiB); + // Signed, so "-5" clamps to the floor (strtoull wraps it to a huge value, which clamps to the maximum). + if (env && *env) + megabytes = VkDeviceSize(std::clamp(std::strtoll(env, nullptr, 10), (long long)kArenaMinMiB, + (long long)kArenaMaxMiB)); ArenaSize size; size.requested = size.bytes = megabytes * kArenaMiB; VkDeviceSize by_buffer = size.requested, by_allocation = size.requested; diff --git a/runtime/test/arena_size_test.cpp b/runtime/test/arena_size_test.cpp index 249af13550..77dcf1f651 100644 --- a/runtime/test/arena_size_test.cpp +++ b/runtime/test/arena_size_test.cpp @@ -29,7 +29,10 @@ int request_without_limits() { CHECK(decide_arena_size("1", none).bytes == 16 * MiB); CHECK(decide_arena_size("0", none).bytes == 16 * MiB); CHECK(decide_arena_size("lots", none).bytes == 16 * MiB); + CHECK(decide_arena_size("-5", none).bytes == 16 * MiB); + CHECK(decide_arena_size("-99999999999999999999", none).bytes == 16 * MiB); CHECK(decide_arena_size("99999", none).bytes == 4095 * MiB); + CHECK(decide_arena_size("99999999999999999999", none).bytes == 4095 * MiB); const ArenaSize s = decide_arena_size("3000", none); CHECK(s.bytes == 3000 * MiB && s.requested == 3000 * MiB && s.capped == arena_cap_none); return 0;