FS#6194 - Squirrel 64bit Integer is parsed wrong into strings

Attached to Project: OpenTTD
Opened by Jan Skoch (The_Dude) - Saturday, 27 December 2014, 11:43 GMT
Last edited by Remko Bijker (Rubidium) - Thursday, 01 January 2015, 21:08 GMT
Type Bug
Category Script
Status Closed
Assigned To No-one
Operating System All
Severity Medium
Priority Normal
Reported Version 1.5.0-beta1
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


This is continuation of bug report  FS#5942  (fixed in r26585).

Squirell now handles int64 well, but when I want to display number higher than uint32_max in gui as string, it fails.

Savegame, sample game script and screenshot enclosed. String code used in example is CURRENCY_LONG, CURENCY_SHORT and COMMA.

I did little research and the results are

in src/script/api/script_text.cpp in function SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
are GSText integer parametres save into this->parami[parameter] = value; (LINE 95)

in src/script/api/script_text.hpp
is parami declared as int parami[SCRIPT_TEXT_MAX_PARAMETERS]; (LINE 132)

So every int64 passed here is cut to int32 (at least on 32-bit system)

Furthermore back in script_text.cpp in function char *ScriptText::_GetEncodedText(char *p, char *lastofp, int &param_count)
are int64 parameters made as uint32 p += seprintf(p, lastofp,":%X", (uint32)this->parami[i]); (LINE 204)

Declaring parami to int64 and removint the (uint32) change type itself does not help though, there is more to that, which I have not discovered.
This task depends upon

Closed by  Remko Bijker (Rubidium)
Thursday, 01 January 2015, 21:08 GMT
Reason for closing:  Fixed
Additional comments about closing:  In r27102 and r27104
Comment by Remko Bijker (Rubidium) - Wednesday, 31 December 2014, 19:36 GMT
I think the attached patch solves the issue; it seems to do so for me, but I don't have a 32 bits environment to properly test it. Could you please test it?
Comment by Jan Skoch (The_Dude) - Thursday, 01 January 2015, 12:58 GMT
Thanks. That's it, it works good!

strtoull is unknown to MSVCRT, so there is needed some define in stdafx.cpp. (diff 1)

Also I found out, that GSList stores again only 32 bit values. As GSList is often used to store various values like scores, it would be good to make it store int64 too. (diff 2)

Both patches works with 32 and 64bit compiled executable on win7 64bit and 32bit works the same on winXP 32bit for me.