changeset 19014:354f3a7968b2 draft

(svn r23870) -Fix [FS#5004]: scripts with a bad comparator could lock up OpenTTD
author rubidium <rubidium@openttd.org>
date Sun, 29 Jan 2012 14:27:21 +0000
parents 22209f8b9d9b
children 0adeb4a38988
files src/3rdparty/squirrel/squirrel/sqbaselib.cpp
diffstat 1 files changed, 4 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/3rdparty/squirrel/squirrel/sqbaselib.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqbaselib.cpp
@@ -538,6 +538,10 @@
 		if(!_sort_compare(v,arr->_values[root],arr->_values[maxChild],func,ret))
 			return false;
 		if (ret < 0) {
+			if (root == maxChild) {
+				v->Raise_Error(_SC("inconsistent compare function"));
+				return false; // We'd be swapping ourselve. The compare function is incorrect
+			}
 			_Swap(arr->_values[root],arr->_values[maxChild]);
 			root = maxChild;
 		}