handle illegal syntax in rule files
authorChristian Thaeter <ct@pipapo.org>
Mon, 8 Oct 2007 07:28:47 +0000 (09:28 +0200)
committerChristian Thaeter <ct@pipapo.org>
Mon, 8 Oct 2007 07:28:47 +0000 (09:28 +0200)
rxpd.c

diff --git a/rxpd.c b/rxpd.c
index c3e506f..702e423 100644 (file)
--- a/rxpd.c
+++ b/rxpd.c
@@ -85,27 +85,32 @@ rxpd_rule_new (const char* buf)
       if (*buf != '#')
         {
           int err;
-          char* rxstart = strchr (buf, ':') + 1;
+          char* rxstart = strchr (buf, ':');
 
-          err = regcomp (&self->rx, rxstart, REG_EXTENDED|REG_ICASE|REG_NOSUB);
-
-          if (!err)
-            {
-              self->string = strdup (buf);
-              if (!self->string) abort();
-            }
+          if (!rxstart)
+            self->string = strdup ("#ERROR: Syntax error, line was neither a comment nor a rule");
           else
             {
-              regfree (&self->rx);
-              char ebuf[256];
-              size_t len = regerror (err, NULL, ebuf, 256);
-              self->string = malloc(len + strlen(buf) + 14);
-              if (!self->string) abort();
-              strcpy (self->string, "#ERROR: ");
-              strcat (self->string, ebuf);
-              strcat (self->string, " in '");
-              strcat (self->string, buf);
-              strcat (self->string, "'");
+              err = regcomp (&self->rx, rxstart+1, REG_EXTENDED|REG_ICASE|REG_NOSUB);
+
+              if (!err)
+                {
+                  self->string = strdup (buf);
+                  if (!self->string) abort();
+                }
+              else
+                {
+                  regfree (&self->rx);
+                  char ebuf[256];
+                  size_t len = regerror (err, NULL, ebuf, 256);
+                  self->string = malloc(len + strlen(buf) + 14);
+                  if (!self->string) abort();
+                  strcpy (self->string, "#ERROR: ");
+                  strcat (self->string, ebuf);
+                  strcat (self->string, " in '");
+                  strcat (self->string, buf);
+                  strcat (self->string, "'");
+                }
             }
         }
       else