regex doesn't set errno and regcomp returns 0 on success and any other
authorJeffrey Stedfast <fejj@ximian.com>
Sun, 15 Apr 2001 21:39:37 +0000 (21:39 +0000)
committerJeffrey Stedfast <fejj@src.gnome.org>
Sun, 15 Apr 2001 21:39:37 +0000 (21:39 +0000)
2001-04-15  Jeffrey Stedfast  <fejj@ximian.com>

* camel-mime-utils.c (header_raw_check_mailing_list): regex
doesn't set errno and regcomp returns 0 on success and any other
value for an error (so don't *just* check for -1).

camel/ChangeLog
camel/camel-mime-utils.c

index c4b0a51..dca89bc 100644 (file)
@@ -1,3 +1,9 @@
+2001-04-15  Jeffrey Stedfast  <fejj@ximian.com>
+
+       * camel-mime-utils.c (header_raw_check_mailing_list): regex
+       doesn't set errno and regcomp returns 0 on success and any other
+       value for an error (so don't *just* check for -1).
+
 2001-04-14  Jeffrey Stedfast  <fejj@ximian.com>
 
        * camel-cipher-context.c: Check to make sure the context is a
index ed65898..1d87300 100644 (file)
@@ -3056,11 +3056,21 @@ header_raw_check_mailing_list(struct _header_raw **list)
        const char *v;
        regex_t pattern;
        regmatch_t match[2];
-       int i;
-
-       for (i=0;i<sizeof(mail_list_magic)/sizeof(mail_list_magic[0]);i++) {
-               if (regcomp(&pattern, mail_list_magic[i].pattern, REG_EXTENDED|REG_ICASE) == -1) {
-                       g_warning("Internal error, compiling regex failed: %s: %s", mail_list_magic[i].pattern, strerror(errno));
+       int i, errcode;
+       
+       for (i = 0; i < sizeof (mail_list_magic) / sizeof (mail_list_magic[0]); i++) {
+               if ((errcode = regcomp (&pattern, mail_list_magic[i].pattern, REG_EXTENDED|REG_ICASE)) != 0) {
+                       char *errstr;
+                       size_t len;
+                       
+                       len = regerror (errcode, pattern, NULL, 0);
+                       errstr = g_malloc0 (len + 1);
+                       regerror (errcode, pattern, errstr, len);
+                       
+                       g_warning ("Internal error, compiling regex failed: %s: %s",
+                                  mail_list_magic[i].pattern, errstr);
+                       g_free (errstr);
+                       
                        continue;
                }