Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A few fixes for Squirrel unchecked return values
- Loading branch information
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
diff --git a/external/squirrel/sqstdlib/sqstdstream.cpp b/external/squirrel/sqstdlib/sqstdstream.cpp | ||
index 1b7a08f..af866a8 100644 | ||
--- a/external/squirrel/sqstdlib/sqstdstream.cpp | ||
+++ b/external/squirrel/sqstdlib/sqstdstream.cpp | ||
@@ -258,7 +258,11 @@ void init_streamclass(HSQUIRRELVM v) | ||
sq_pushstring(v,_SC("std_stream"),-1); | ||
if(SQ_FAILED(sq_get(v,-2))) { | ||
sq_pushstring(v,_SC("std_stream"),-1); | ||
- sq_newclass(v,SQFalse); | ||
+ if(SQ_FAILED(sq_newclass(v,SQFalse))) | ||
+ { | ||
+ throw "Failed to create new std_stream class"; | ||
+ return; | ||
+ } | ||
sq_settypetag(v,-1,(SQUserPointer)SQSTD_STREAM_TYPE_TAG); | ||
SQInteger i = 0; | ||
while(_stream_methods[i].name != 0) { | ||
@@ -266,10 +270,16 @@ void init_streamclass(HSQUIRRELVM v) | ||
sq_pushstring(v,f.name,-1); | ||
sq_newclosure(v,f.f,0); | ||
sq_setparamscheck(v,f.nparamscheck,f.typemask); | ||
- sq_newslot(v,-3,SQFalse); | ||
+ if(SQ_FAILED(sq_newslot(v,-3,SQFalse)) | ||
+ { | ||
+ throw "Failed to create new table slot for stream_method"; | ||
+ } | ||
i++; | ||
} | ||
- sq_newslot(v,-3,SQFalse); | ||
+ if(SQ_FAILED(sq_newslot(v,-3,SQFalse)) | ||
+ { | ||
+ throw "Failed to create new table slot for stream"; | ||
+ } | ||
sq_pushroottable(v); | ||
sq_pushstring(v,_SC("stream"),-1); | ||
sq_pushstring(v,_SC("std_stream"),-1); | ||
@@ -306,7 +316,10 @@ SQRESULT declare_stream(HSQUIRRELVM v,const SQChar* name,SQUserPointer typetag,c | ||
sq_newslot(v,-3,SQFalse); | ||
i++; | ||
} | ||
- sq_newslot(v,-3,SQFalse); | ||
+ if(SQ_FAILED(sq_newslot(v,-3,SQFalse)) | ||
+ { | ||
+ throw "Failed to create new table slot" | ||
+ } | ||
sq_pop(v,1); | ||
|
||
i = 0; | ||
@@ -317,7 +330,10 @@ SQRESULT declare_stream(HSQUIRRELVM v,const SQChar* name,SQUserPointer typetag,c | ||
sq_newclosure(v,f.f,0); | ||
sq_setparamscheck(v,f.nparamscheck,f.typemask); | ||
sq_setnativeclosurename(v,-1,f.name); | ||
- sq_newslot(v,-3,SQFalse); | ||
+ if(SQ_FAILED(sq_newslot(v,-3,SQFalse)) | ||
+ { | ||
+ throw "Failed to create new table slot for global"; | ||
+ } | ||
i++; | ||
} | ||
//register the class in the target table | ||
diff --git a/external/squirrel/sqstdlib/sqstdsystem.cpp b/external/squirrel/sqstdlib/sqstdsystem.cpp | ||
index 40f78d7..b5359b6 100644 | ||
--- a/external/squirrel/sqstdlib/sqstdsystem.cpp | ||
+++ b/external/squirrel/sqstdlib/sqstdsystem.cpp | ||
@@ -140,7 +140,10 @@ SQInteger sqstd_register_systemlib(HSQUIRRELVM v) | ||
sq_newclosure(v,systemlib_funcs[i].f,0); | ||
sq_setparamscheck(v,systemlib_funcs[i].nparamscheck,systemlib_funcs[i].typemask); | ||
sq_setnativeclosurename(v,-1,systemlib_funcs[i].name); | ||
- sq_newslot(v,-3,SQFalse); | ||
+ if(SQ_FAILED(sq_newslot(v,-3,SQFalse)) | ||
+ { | ||
+ // Could not create table slot | ||
+ } | ||
i++; | ||
} | ||
return 1; |