SilcRegex: Fixed silc_regex to return correct value for optional args
authorPekka Riikonen <priikone@silcnet.org>
Sun, 21 Sep 2008 12:32:04 +0000 (15:32 +0300)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 21 Sep 2008 12:32:04 +0000 (15:32 +0300)
In grouped expressions, optional, non-matched arguments didn't have their
value set to NULL as documented.  Set all arguments by default to NULL.

lib/silcutil/silcregex.c

index 8444969560c561eca7c4cc046e15a2226b142371..3c83ed783d693149003ffa7cdaa47564c834952e 100644 (file)
@@ -2411,6 +2411,7 @@ SilcBool silc_regex_va(const char *string, SilcUInt32 string_len,
       silc_regex_free(&reg);
       return FALSE;
     }
+    silc_buffer_set(match, NULL, 0);
     rets[c++] = match;
 
     while ((buf = va_arg(va, SilcBuffer))) {
@@ -2421,6 +2422,7 @@ SilcBool silc_regex_va(const char *string, SilcUInt32 string_len,
        silc_regex_free(&reg);
        return FALSE;
       }
+      silc_buffer_set(buf, NULL, 0);
       rets[c++] = buf;
     }
 
@@ -2444,10 +2446,8 @@ SilcBool silc_regex_va(const char *string, SilcUInt32 string_len,
 
   /* Return matches */
   for (i = 0; i < c; i++) {
-    if (m[i].start == -1) {
-      silc_buffer_set(rets[i], NULL, 0);
+    if (m[i].start == -1)
       continue;
-    }
     silc_buffer_set(rets[i], (unsigned char *)string + m[i].start,
                    m[i].end - m[i].start);
   }