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

Squirrel integer compare returns wrong result #3954

Closed
DorpsGek opened this issue Jul 16, 2010 · 1 comment
Closed

Squirrel integer compare returns wrong result #3954

DorpsGek opened this issue Jul 16, 2010 · 1 comment
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)

Comments

@DorpsGek
Copy link
Member

Attila7 opened the ticket and wrote:

The Squirrel statement
(13725 > -2147483648)
produces false.

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);

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.

Reported version: trunk
Operating system: Windows


This issue was imported from FlySpray: https://bugs.openttd.org/task/3954
@DorpsGek
Copy link
Member Author

Rubidium closed the ticket.

Reason for closing: Fixed

In r20162


This comment was imported from FlySpray: https://bugs.openttd.org/task/3954

@DorpsGek DorpsGek added flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) Squirrel labels Apr 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)
Projects
None yet
Development

No branches or pull requests

1 participant