Merge pull request #120 from VasiliyRyabtsev/fix/array-resize

Raise error for negative size in array_resize()
This commit is contained in:
Alberto Demichelis 2017-11-29 02:04:16 +08:00 committed by GitHub
commit 938655a90b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -542,9 +542,13 @@ static SQInteger array_resize(HSQUIRRELVM v)
SQObject &nsize = stack_get(v, 2);
SQObjectPtr fill;
if(sq_isnumeric(nsize)) {
SQInteger sz = tointeger(nsize);
if (sz<0)
return sq_throwerror(v, _SC("resizing to negative length"));
if(sq_gettop(v) > 2)
fill = stack_get(v, 3);
_array(o)->Resize(tointeger(nsize),fill);
_array(o)->Resize(sz,fill);
return 0;
}
return sq_throwerror(v, _SC("size must be a number"));