Просмотр исходного кода

The string_find_close_quote now accepts an optional parameter to indicate the quote character.
Fix invalid array access on string_find_delimiter

mingodad 10 лет назад
Родитель
Сommit
e155bd1feb
1 измененных файлов с 7 добавлено и 6 удалено
  1. 7 6
      SquiLu/squirrel/sqbaselib.cpp

+ 7 - 6
SquiLu/squirrel/sqbaselib.cpp

@@ -1550,15 +1550,16 @@ static SQRESULT string_find_close_quote(HSQUIRRELVM v) {
     SQ_FUNC_VARS(v);
     SQ_GET_STRING(v, 1, src);
     SQ_OPT_INTEGER(v, 2, init, 0);
+    SQ_OPT_INTEGER(v, 3, quote, '"');
     if(init >= src_size) return sq_throwerror(v, _SC("invalid start position"));
 
     for(; init < src_size; ++init) {
-        if(src[init] == '"'){
-             if(src[init+1] == '"') ++init; //skip quoted quote
+        if(src[init] == quote){
+             if(src[init+1] == quote) ++init; //skip quoted quote
              else break;
         }
     }
-    if(src[init] != '"') init = -1;
+    if(src[init] != quote) init = -1;
     sq_pushinteger(v, init);
     return 1;
 }
@@ -1576,10 +1577,10 @@ static SQRESULT string_find_delimiter(HSQUIRRELVM v) {
             int i = 1;
             if(src[init-i] != escape_char) break;
             while(src[init- ++i] == escape_char);
-            if(((i-1) % 2)) break; //non escaped escaped_char
+            if(((i-1) % 2) == 0) break; //non escaped escaped_char
         }
     }
-    if(src[init] != delimiter) init = -1;
+    if((init >= src_size) || (src[init] != delimiter)) init = -1;
     sq_pushinteger(v, init);
     return 1;
 }
@@ -1891,7 +1892,7 @@ SQRegFunction SQSharedState::_string_default_delegate_funcz[]={
 	{_SC("find"),string_find,-2, _SC("s s n ")},
 	{_SC("indexOf"),string_find,-2, _SC("s s n ")},
 	{_SC("find_lua"),string_find_lua,-2, _SC("ss a|t|c nb")},
-	{_SC("find_close_quote"),string_find_close_quote,-1, _SC("sn")},
+	{_SC("find_close_quote"),string_find_close_quote,-1, _SC("sni")},
 	{_SC("find_delimiter"),string_find_delimiter,4, _SC("siin")},
 	{_SC("gsub"),string_gsub,-3, _SC("s s s|a|t|c n")},
 	{_SC("gmatch"),string_gmatch, 3, _SC("s s c")},