Fix: handle over/underflows in (int) TLuaInterpreter::getVerifiedInt(…)#8924
Conversation
…...) #### Brief overview of PR changes/additions Revises `(int) TLuaInterpreter::getVerifiedInt(...)` so it checks and errors out should the call of `lua_tointeger(...)` return a value outside the range that can be conveyed as an `int` (actually `int32_t`). This function actaully returns a `lua_Integer` which is a `typedef` of `ptrdiff_t` - which is a signed 32-bit integer on 32-Bit Windows OS but is actually a signed 64-bit integer on all the platforms we currently support. #### Motivation for adding to Mudlet Prevent odd behaviour in the event of integer over/underflows. #### Other info (issues closed, discussion etc) This came about from the changes in 3609e94 as part of Mudlet#4661 in 2021 (which seemes to assume `getVerifiedInt(...)` did actually return an `int`) - ironically I had actually fixed the conversion of 64-bit to 32-bit integers for exit weights in the earlier Mudlet#2106 but which that PR undid. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
|
Hey there! Thanks for helping Mudlet improve. 🌟 Test versionsYou can directly test the changes here:
No need to install anything - just unzip and run. |
Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
|
PR #8924 Review Core overflow check in getVerifiedInt() looks good - std::numeric_limits, explicit static_cast, correct ptrdiff_t claim per Lua 5.1 headers. Discord callsite cleanup correctly removes redundant qMin/static_cast clamping. Protects all ~320 existing getVerifiedInt() callsites from silent truncation. Two suggestions:
Pre-existing observations (not from this PR, potential follow-ups):
|
Signed-off-by: Stephen Lyons <slysven@virginmedia.com>




Brief overview of PR changes/additions
Revises
(int) TLuaInterpreter::getVerifiedInt(...)so it checks and errors out should the call oflua_tointeger(...)return a value outside the range that can be conveyed as anint(actuallyint32_t). This function actually returns alua_Integerwhich is atypedefofptrdiff_t- which is a signed 32-bit integer on 32-Bit Windows OS but is actually a signed 64-bit integer on all the platforms we currently support.Motivation for adding to Mudlet
Prevent odd behaviour in the event of integer over/underflows.
Other info (issues closed, discussion etc)
This came about from the changes in 3609e94 as part of #4661 in 2021 (which seemes to assume
getVerifiedInt(...)did actually return anint) - ironically I had actually fixed the conversion of 64-bit to 32-bit integers for exit weights in the earlier #2106 but which that PR undid.