Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FS#948 - lua: on 64bit targets integer number truncation may occur #5896

Closed
openwrt-bot opened this issue Aug 3, 2017 · 3 comments
Closed
Labels
core packages pull request/issue for core (in-tree) packages flyspray

Comments

@openwrt-bot
Copy link

vcalvis:

On 64bit target implementations (eg x86_64) and with LNUM on int32
mode (default), assignation of an integer number greater than
UINT_MAX (ie 4294967295), but lesser or equal than UINT_MAX +
0x7FFFFFFF + 1 (ie 6442450943) to a variable does result in
truncation of the final value stored in memory.

E.g.:
> n=4294967296; print(n)
0
> n=6442450943; print(n)
2147483647

Cause:
LNUM does perform a C-Style cast in the intermediate function wrapper
used to check for the fitness of numbers. This cast is not only unnecessary
but also brings on undefined behaviour on 64bit target implementations
where INT's and LONG's are of size 32 and 64bit respectively.

Fix:
Removal of the unnecessary cast in wrapper does bring back the 'overflow detection'.

Regards, Víctor Calvís.

@openwrt-bot
Copy link
Author

ptpt52:

could u provide a patch?

@aparcar aparcar added the core packages pull request/issue for core (in-tree) packages label Feb 22, 2022
@hauke
Copy link
Member

hauke commented Feb 26, 2023

I think the problem was fixed some time ago in 4bb9af4

root@OpenWrt:/# lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio (double int32)
> n=4294967296; print(n)
4294967296
> n=6442450943; print(n)
6442450943

I used this configuration:

CONFIG_TARGET_x86=y
CONFIG_TARGET_x86_64=y
CONFIG_TARGET_x86_64_DEVICE_generic=y
CONFIG_PACKAGE_lua=y
CONFIG_PACKAGE_lua5.3=y

@hauke hauke closed this as completed Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core packages pull request/issue for core (in-tree) packages flyspray
Projects
None yet
Development

No branches or pull requests

3 participants