be a little bit more stringent in checking input strings
[claws.git] / src / string_match.c
index 2e4ca3cca477e305a13549f497f9fa006c9ef75c..114fb593c414b5621ec237a831f981d6c285e9f1 100644 (file)
@@ -17,7 +17,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-
+#include <glib.h>
 #include "string_match.h"
 
 
@@ -28,6 +28,9 @@ int string_match_regexp(char * txt, char * rexp,
        regex_t re;
        int problem;
 
+       g_return_val_if_fail(txt, 0);
+       g_return_val_if_fail(rexp, 0);
+
        problem = regcomp(&re, rexp, cflags);  
        if (problem == 0) {
                problem = regexec(&re, txt, size, matches, eflags);
@@ -41,6 +44,9 @@ int string_remove_match(char * txt, char * rexp, int cflags, int eflags)
        regmatch_t matches[STRING_MATCH_MR_SIZE];
        int foundp;
 
+       g_return_val_if_fail(txt, -1);
+       g_return_val_if_fail(rexp, -1);
+
        if (strlen(txt) > 0 && strlen(rexp) > 0) {
                foundp = string_match_regexp(txt, rexp, STRING_MATCH_MR_SIZE, 
                                             matches, cflags, eflags);
@@ -66,6 +72,9 @@ int string_remove_all_matches(char * txt, char * rexp, int cflags, int eflags)
        int pos = 0;
        int pos0 = pos;
 
+       g_return_val_if_fail(txt, 0);
+       g_return_val_if_fail(rexp, 0);
+
        while (pos0 >= 0 && pos < strlen(txt) && strlen(txt) > 0) {
                /* printf("%s %d:%d\n", txt, pos0, pos); */
                pos0 = string_remove_match(txt + pos, rexp, cflags, eflags);