]> git.notmuchmail.org Git - notmuch/commitdiff
xregcomp: don't consider every regex compilation failure an internal error.
authorDavid Bremner <bremner@debian.org>
Sun, 23 Oct 2011 20:52:19 +0000 (17:52 -0300)
committerDavid Bremner <bremner@debian.org>
Mon, 31 Oct 2011 02:10:38 +0000 (23:10 -0300)
This pushes the error handling up one step, but makes the function
more flexible. Running out of memory still triggers an internal error,
in the spirit of other xutils functions.

notmuch-restore.c
util/xutil.c
util/xutil.h

index ff1ebab10d758b963a4774f91e89a43c6be3c50f..13b4325a882667b9178e432d87de14f94f1fb85c 100644 (file)
@@ -88,9 +88,10 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
      * non-space characters for the message-id, then one or more
      * spaces, then a list of space-separated tags as a sequence of
      * characters within literal '(' and ')'. */
      * non-space characters for the message-id, then one or more
      * spaces, then a list of space-separated tags as a sequence of
      * characters within literal '(' and ')'. */
-    xregcomp (&regex,
-             "^([^ ]+) \\(([^)]*)\\)$",
-             REG_EXTENDED);
+    if ( xregcomp (&regex,
+                  "^([^ ]+) \\(([^)]*)\\)$",
+                  REG_EXTENDED) )
+       INTERNAL_ERROR("compile time constant regex failed.");
 
     while ((line_len = getline (&line, &line_size, input)) != -1) {
        regmatch_t match[3];
 
     while ((line_len = getline (&line, &line_size, input)) != -1) {
        regmatch_t match[3];
index 15ff7650c3b5cc7782726c88f781ec20106baf95..ac496daf17f7c6f5f1dab6aabe8ff7e6dd8f4793 100644 (file)
@@ -99,7 +99,7 @@ xstrndup (const char *s, size_t n)
     return ret;
 }
 
     return ret;
 }
 
-void
+int
 xregcomp (regex_t *preg, const char *regex, int cflags)
 {
     int rerr;
 xregcomp (regex_t *preg, const char *regex, int cflags)
 {
     int rerr;
@@ -110,9 +110,12 @@ xregcomp (regex_t *preg, const char *regex, int cflags)
        char *error = xmalloc (error_size);
 
        regerror (rerr, preg, error, error_size);
        char *error = xmalloc (error_size);
 
        regerror (rerr, preg, error, error_size);
-       INTERNAL_ERROR ("compiling regex %s: %s\n",
+       fprintf (stderr, "compiling regex %s: %s\n",
                        regex, error);
                        regex, error);
+       free (error);
+       return 1;
     }
     }
+    return 0;
 }
 
 int
 }
 
 int
index fd77f733a5b33a35dfb32bcb3055c0c1147a5303..92992564487ed26ad6b363cbd90817988a726738 100644 (file)
@@ -43,7 +43,8 @@ xstrdup (const char *s);
 char *
 xstrndup (const char *s, size_t n);
 
 char *
 xstrndup (const char *s, size_t n);
 
-void
+/* Returns 0 for successful compilation, 1 otherwise */
+int
 xregcomp (regex_t *preg, const char *regex, int cflags);
 
 int
 xregcomp (regex_t *preg, const char *regex, int cflags);
 
 int