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

string.format more than 0x80000000 (32bit limit) #1667

Closed
rifleh700 opened this issue Sep 15, 2020 · 6 comments · Fixed by #1672 or #1691
Closed

string.format more than 0x80000000 (32bit limit) #1667

rifleh700 opened this issue Sep 15, 2020 · 6 comments · Fixed by #1672 or #1691
Labels
bug Something isn't working
Milestone

Comments

@rifleh700
Copy link

rifleh700 commented Sep 15, 2020

Describe the bug
string.format("%X", num) don't work with numbers more than 0x80000000.

To reproduce

iprint("0x7FFFFFFF: ", string.format("%X", 0x7FFFFFFF)) -- 7FFFFFFF
iprint("0x80000000: ", string.format("%X", 0x80000000)) -- 80000000
iprint("0x80000001: ", string.format("%X", 0x80000001)) -- 80000000 (just floored to 0x80000000)

Version
server: 1.5.7-20642
client: 1.5.7-20632
os: windows 7 32bit

Additional context
On older builds it works normally (i.e. server v1.5.7-release-20582)

@rifleh700 rifleh700 added the bug Something isn't working label Sep 15, 2020
@Pirulax
Copy link
Contributor

Pirulax commented Sep 17, 2020

~~the lua module is 32 bit on client side(and on the 32 bit server).
Possible solution would be to, somewhere in the C code of string.format, change that int to long long. Not sure how good of an idea that is tho / how useful it would be.

Edit: Not sure if tostring works? Perhaps try rounding it with math.floor to get the same result. If it still doesnt work try hacking it together with bitwise functions that are available in MTA. (What I mean is that you, in theory could bitshift a > 32 bit number into 2x < 32 bit numbers, and then tostring(lowerHalf) .. tostring(upperHalf)
Im pretty sure actually that there is some kind of workaround useful function on the Wiki.~~

Edit: Didn't read the "additional context" section. My bad.

@qaisjp
Copy link
Contributor

qaisjp commented Sep 17, 2020

On older builds it works normally (i.e. server v1.5.7-release-20582)

We need to find the commit that causes this

@StrixG
Copy link
Contributor

StrixG commented Sep 17, 2020

@qaisjp c174c73
r20627

@qaisjp
Copy link
Contributor

qaisjp commented Sep 17, 2020

Nice. Should we update the build server again and hope for the best @ccw808?

@ccw808
Copy link
Member

ccw808 commented Sep 17, 2020

Yes, please apply the update

@qaisjp qaisjp added this to the 1.5.8 milestone Sep 21, 2020
@qaisjp qaisjp mentioned this issue Sep 21, 2020
36 tasks
sbx320 added a commit to sbx320/mtasa-blue that referenced this issue Sep 21, 2020
sbx320 added a commit that referenced this issue Sep 21, 2020
@sbx320
Copy link
Member

sbx320 commented Sep 21, 2020

Updating the build server didn't change anything.

However looking at the code for string.format, it always casted to a long when formatting as a hex number. Changing that to a long long via the configuration option solves the issue.

I'm however not sure why this has ever worked. My best guess is some change in the optimizer (previously doing a transparent long -> long long by skipping the cast, and now doing the direct long -> int "conversion"). In any case we can just make Lua use long long for formatting, as all C++11 compilers are required to provide long long. Please retest in next nightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
6 participants