882a2046 computes lo + esp_random() % (uint32_t)(hi - lo + 1) in 32-bit
Lua integers (LUA_32BITS). hi - lo + 1 overflows for spans past 2^31, and
for random(math.mininteger, math.maxinteger) it is 2^32, which is 0: the
ESP32-S3 compiler at -O2 emits sub / addi 1 / remu, and remu by zero is an
IntegerDivideByZero exception, so any app could panic the device with one
call. UBSan flags the same expression as signed overflow on the host.
The range math moves into src/ui-touch/LuaRandomRange.h and is done in
unsigned 32-bit arithmetic; a span of 0 means every value. random(),
random(n) and random(lo, hi) behave as documented otherwise.
test/test_lua_random_range.cpp (clean under UBSan) covers 1..n with every
value seen, (1, 1), reversed and negative ranges and both ends of int32.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>