fix(lua): Use lua_tonumber
to support 32-bit platforms
#4369
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously,
luaC_tovalue
usedlua_tointeger
for variables of type "derive", "counter", and "absolute". However, on 32-bit platforms,lua_Integer
may be only 32 bits wide, so if you setvalues
to a value larger than 2^31-1 from Lua, the value oflua_tointeger
will be unspecified.This commit changes the code to use
lua_tonumber
on 32-bit platforms, which returns a float, which will then be cast to the (typedef'ed to[u]int64_t
) integer typesderive_t
, counter_t, and
absolute_t`, ensuring that large values are not truncated.When
lua_Integer
is 64 bits wide, the code will still uselua_tointeger
to ensure that integers between 2^53 and 2^63-1 do not lose precision on newer versions of Lua with dedicated integer types.I've only personally tested this patch on a 32-bit platform, but in theory this patch shouldn't affect 64-bit platforms at all.
ChangeLog: Lua plugin: Support "derive", "counter", and "absolute" values >2^31 on 32-bit platforms.