Преглед изворни кода

Fix for segfault when the pattern is an empty string

mingodad пре 8 година
родитељ
комит
1e2b2deb0a
1 измењених фајлова са 7 додато и 1 уклоњено
  1. 7 1
      SquiLu/sqstdlib/sqstdrex.cpp

+ 7 - 1
SquiLu/sqstdlib/sqstdrex.cpp

@@ -585,10 +585,16 @@ static const SQChar *sqstd_rex_matchnode(SQRex* exp,SQRexNode *node,const SQChar
 /* public api */
 SQRex *sqstd_rex_compile(const SQChar *pattern,const SQChar **error)
 {
+    SQInteger plen = (SQInteger)scstrlen(pattern) * sizeof(SQChar);
+    if(plen == 0)
+    {
+        *error = _SC("empty pattern");
+        return NULL;
+    }
 	SQRex * volatile exp = (SQRex *)sq_malloc(sizeof(SQRex)); // "volatile" is needed for setjmp()
 	exp->_eol = exp->_bol = NULL;
 	exp->_p = pattern;
-	exp->_nallocated = (SQInteger)scstrlen(pattern) * sizeof(SQChar);
+	exp->_nallocated = plen;
 	exp->_nodes = (SQRexNode *)sq_malloc(exp->_nallocated * sizeof(SQRexNode));
 	exp->_nsize = 0;
 	exp->_matches = 0;