diff options
author | rubidium <rubidium@openttd.org> | 2012-04-18 19:22:32 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2012-04-18 19:22:32 +0000 |
commit | a355e123fcbb6110ba0820cb95f821f33e39c906 (patch) | |
tree | 792d51c1f83ed192ee22739f2d5661cb351aea4b | |
parent | 8d5685679111ee465c6fcafa94322ead7ccd11e2 (diff) | |
download | openttd-a355e123fcbb6110ba0820cb95f821f33e39c906.tar.xz |
(svn r24153) -Fix [FS#5160]: [Squirrel] Crash when trying to create an array with negative size
-rw-r--r-- | src/3rdparty/squirrel/squirrel/sqbaselib.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/3rdparty/squirrel/squirrel/sqbaselib.cpp b/src/3rdparty/squirrel/squirrel/sqbaselib.cpp index 486b888b5..66a81edb4 100644 --- a/src/3rdparty/squirrel/squirrel/sqbaselib.cpp +++ b/src/3rdparty/squirrel/squirrel/sqbaselib.cpp @@ -210,16 +210,22 @@ static SQInteger base_suspend(HSQUIRRELVM v) static SQInteger base_array(HSQUIRRELVM v) { SQArray *a; - SQObject &size = stack_get(v,2); + SQInteger nInitialSize = tointeger(stack_get(v,2)); + SQInteger ret = 1; + if (nInitialSize < 0) { + v->Raise_Error(_SC("can't create/resize array with/to size %d"), nInitialSize); + nInitialSize = 0; + ret = -1; + } if(sq_gettop(v) > 2) { a = SQArray::Create(_ss(v),0); - a->Resize(tointeger(size),stack_get(v,3)); + a->Resize(nInitialSize,stack_get(v,3)); } else { - a = SQArray::Create(_ss(v),tointeger(size)); + a = SQArray::Create(_ss(v),nInitialSize); } v->Push(a); - return 1; + return ret; } static SQInteger base_type(HSQUIRRELVM v) |