浏览代码

Never assume the format is actually a string.

The invoker should at least know that the value he specified is not of the correct type.
Sandu Liviu Catalin 9 年之前
父节点
当前提交
795af921cc
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      sqstdlib/sqstdstring.cpp

+ 4 - 1
sqstdlib/sqstdstring.cpp

@@ -69,7 +69,10 @@ SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen
     const SQChar *format;
     SQChar *dest;
     SQChar fmt[MAX_FORMAT_LEN];
-    sq_getstring(v,nformatstringidx,&format);
+    const SQRESULT res = sq_getstring(v,nformatstringidx,&format);
+    if (SQ_FAILED(res)) {
+        return res; // propagate the error
+    }
     SQInteger format_size = sq_getsize(v,nformatstringidx);
     SQInteger allocated = (format_size+2)*sizeof(SQChar);
     dest = sq_getscratchpad(v,allocated);