Possible Squirrel bug - fixed in r20162

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Possible Squirrel bug - fixed in r20162

Post by Attila7 »

Can someone please very that the Squirrel statement
(13725 > -2147483648)
produces false?

In case it is verified, the culprit seems to be at line 199 of sqvm.cpp which reads:
_RET_SUCCEED(_integer(o1)-_integer(o2));

This code is trying to compare two integers, but the operation will cause the result to be an overflow -ve number and the result of the comparison will be false.

On line 201 the comparison of floats is correct:
_RET_SUCCEED((_float(o1)<_float(o2))?-1:1);

Line 199 should be modified to read:
_RET_SUCCEED((_integer(o1)<_integer(o2))?-1:(_integer(o1)==_integer(o2))?0:1);

I am pretty sure this is a bug this time. :)
Last edited by Attila7 on 16 Jul 2010 19:32, edited 1 time in total.
Attila
"Artificial intelligence is no match for natural stupidity."
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Possible Squirrel bug

Post by Kogut »

It may be kind of integer overflow.
http://en.wikipedia.org/wiki/Integer_overflow
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Attila7
Engineer
Engineer
Posts: 37
Joined: 31 May 2010 21:06

Re: Possible Squirrel bug

Post by Attila7 »

Umm, not sure why you posted the link. I know it is an integer overflow problem as stated:
This code is trying to compare two integers, but the operation will cause the result to be an overflow -ve number and the result of the comparison will be false.
I have this fixed in my version and it now works fine.

Note that although I am using the max -ve 32-bit number in my example, the comparison will give the wrong result whenever you compare A to B where A - B > 2147483647.
Attila
"Artificial intelligence is no match for natural stupidity."
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 5 guests