diff options
| author | Romain PINSOLLE <romain.pins@gmail.com> | 2026-11-24 16:11:47 +0100 |
|---|---|---|
| committer | Romain PINSOLLE <romain.pins@gmail.com> | 2026-11-24 16:11:47 +0100 |
| commit | 49e6392c9e6ee45cfce8ef7b690aaa7fc223ce0d (patch) | |
| tree | 86b40f1c994bad4189b6d31621833d240ddf16df /runtime/src | |
| parent | a28927849adb4e40dfdec8c32fb6758dcd205a37 (diff) | |
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.
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/arena_size.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/runtime/src/arena_size.h b/runtime/src/arena_size.h index 8f4ca4caf..196b03e3e 100644 --- a/runtime/src/arena_size.h +++ b/runtime/src/arena_size.h | |||
| @@ -60,7 +60,10 @@ struct ArenaSize { | |||
| 60 | // invalid Vulkan, while one under 16 MiB is only small (and no conformant device reports under 1 GiB). | 60 | // invalid Vulkan, while one under 16 MiB is only small (and no conformant device reports under 1 GiB). |
| 61 | inline ArenaSize decide_arena_size(const char* env, const ArenaLimits& limits, VkDeviceSize allocation_overhead = 0) { | 61 | inline ArenaSize decide_arena_size(const char* env, const ArenaLimits& limits, VkDeviceSize allocation_overhead = 0) { |
| 62 | VkDeviceSize megabytes = kArenaDefaultMiB; | 62 | VkDeviceSize megabytes = kArenaDefaultMiB; |
| 63 | if (env && *env) megabytes = std::clamp<VkDeviceSize>(std::strtoull(env, nullptr, 10), kArenaMinMiB, kArenaMaxMiB); | 63 | // Signed, so "-5" clamps to the floor (strtoull wraps it to a huge value, which clamps to the maximum). |
| 64 | if (env && *env) | ||
| 65 | megabytes = VkDeviceSize(std::clamp<long long>(std::strtoll(env, nullptr, 10), (long long)kArenaMinMiB, | ||
| 66 | (long long)kArenaMaxMiB)); | ||
| 64 | ArenaSize size; | 67 | ArenaSize size; |
| 65 | size.requested = size.bytes = megabytes * kArenaMiB; | 68 | size.requested = size.bytes = megabytes * kArenaMiB; |
| 66 | VkDeviceSize by_buffer = size.requested, by_allocation = size.requested; | 69 | VkDeviceSize by_buffer = size.requested, by_allocation = size.requested; |