Mercurial > hg > openttd
changeset 15509:364fe72831fc draft
(svn r20162) -Fix [FS#3954]: integer comparison failed in case the difference was more than "MAX_UINT"/2
author | rubidium <rubidium@openttd.org> |
---|---|
date | Fri, 16 Jul 2010 17:42:58 +0000 |
parents | 1a960beff6b4 |
children | a215a8588379 |
files | bin/ai/regression/regression.nut bin/ai/regression/regression.txt src/3rdparty/squirrel/squirrel/sqvm.cpp |
diffstat | 3 files changed, 79 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/bin/ai/regression/regression.nut +++ b/bin/ai/regression/regression.nut @@ -1757,6 +1757,48 @@ print(" GetCargoType(): " + AISubsidy.GetCargoType(subsidy_id)); } +function Regression::Math() +{ + print(""); + print("--Math--"); + print(" -2147483648 < -2147483647: " + (-2147483648 < -2147483647)); + print(" -2147483648 < -1 : " + (-2147483648 < -1 )); + print(" -2147483648 < 0 : " + (-2147483648 < 0 )); + print(" -2147483648 < 1 : " + (-2147483648 < 1 )); + print(" -2147483648 < 2147483647: " + (-2147483648 < 2147483647)); + + print(" -2147483647 < -2147483648: " + (-2147483647 < -2147483648)); + print(" -1 < -2147483648: " + (-1 < -2147483648)); + print(" 0 < -2147483648: " + ( 0 < -2147483648)); + print(" 1 < -2147483648: " + ( 1 < -2147483648)); + print(" 2147483647 < -2147483648: " + ( 2147483647 < -2147483648)); + + print(" -1 > 2147483647: " + (-1 > 2147483647)); + print(" -1 > 1 : " + (-1 > 1 )); + print(" -1 > 0 : " + (-1 > 0 )); + print(" -1 > -1 : " + (-1 > -1 )); + print(" -1 > -2147483648: " + (-1 > -2147483648)); + + print(" 1 > 2147483647: " + ( 1 > 2147483647)); + print(" 1 > 1 : " + ( 1 > 1 )); + print(" 1 > 0 : " + ( 1 > 0 )); + print(" 1 > -1 : " + ( 1 > -1 )); + print(" 1 > -2147483648: " + ( 1 > -2147483648)); + + print(" 2147483647 > 2147483646: " + ( 2147483647 > 2147483646)); + print(" 2147483647 > 1 : " + ( 2147483647 > 1 )); + print(" 2147483647 > 0 : " + ( 2147483647 > 0 )); + print(" 2147483647 > -1 : " + ( 2147483647 > -1 )); + print(" 2147483647 > -2147483648: " + ( 2147483647 > -2147483648)); + + print(" 2147483646 > 2147483647: " + ( 2147483646 > 2147483647)); + print(" 1 > 2147483647: " + ( 1 > 2147483647)); + print(" 0 > 2147483647: " + ( 0 > 2147483647)); + print(" -1 > 2147483647: " + (-1 > 2147483647)); + print(" -2147483648 > 2147483647: " + (-2147483648 > 2147483647)); + + print(" 13725 > -2147483648: " + ( 13725 > -2147483648)); +} function Regression::Start() { @@ -1822,5 +1864,7 @@ } } print(" IsEventWaiting: false"); + + this.Math(); }
--- a/bin/ai/regression/regression.txt +++ b/bin/ai/regression/regression.txt @@ -8632,4 +8632,37 @@ GetEventType: 6 Unknown Event IsEventWaiting: false + +--Math-- + -2147483648 < -2147483647: true + -2147483648 < -1 : true + -2147483648 < 0 : true + -2147483648 < 1 : true + -2147483648 < 2147483647: true + -2147483647 < -2147483648: false + -1 < -2147483648: false + 0 < -2147483648: false + 1 < -2147483648: false + 2147483647 < -2147483648: false + -1 > 2147483647: false + -1 > 1 : false + -1 > 0 : false + -1 > -1 : false + -1 > -2147483648: true + 1 > 2147483647: false + 1 > 1 : false + 1 > 0 : true + 1 > -1 : true + 1 > -2147483648: true + 2147483647 > 2147483646: true + 2147483647 > 1 : true + 2147483647 > 0 : true + 2147483647 > -1 : true + 2147483647 > -2147483648: true + 2147483646 > 2147483647: false + 1 > 2147483647: false + 0 > 2147483647: false + -1 > 2147483647: false + -2147483648 > 2147483647: false + 13725 > -2147483648: true ERROR: The AI died unexpectedly.
--- a/src/3rdparty/squirrel/squirrel/sqvm.cpp +++ b/src/3rdparty/squirrel/squirrel/sqvm.cpp @@ -186,7 +186,8 @@ case OT_STRING: _RET_SUCCEED(scstrcmp(_stringval(o1),_stringval(o2))); case OT_INTEGER: - _RET_SUCCEED(_integer(o1)-_integer(o2)); + /* FS#3954: wrong integer comparison */ + _RET_SUCCEED((_integer(o1)<_integer(o2))?-1:(_integer(o1)==_integer(o2))?0:1); case OT_FLOAT: _RET_SUCCEED((_float(o1)<_float(o2))?-1:1); case OT_TABLE: