Fixed some memory leaks.
[pspp-builds.git] / src / format.c
index 37e691a4a7ae20f0483de8a262f1851012ed1a0b..744cd6feccaf3644fb118cc9cdfb0c51c4f6a3f3 100644 (file)
@@ -20,7 +20,7 @@
 #include <config.h>
 #include "format.h"
 #include <ctype.h>
-#include <assert.h>
+#include "error.h"
 #include <stdlib.h>
 #include "error.h"
 #include "lexer.h"
@@ -49,7 +49,7 @@ parse_format_specifier_name (const char **cp, int allow_xt)
   char *sp, *ep;
   int idx;
 
-  sp = ep = ds_value (&tokstr);
+  sp = ep = ds_c_str (&tokstr);
   while (isalpha ((unsigned char) *ep))
     ep++;
 
@@ -58,7 +58,7 @@ parse_format_specifier_name (const char **cp, int allow_xt)
       /* Find format. */
       for (idx = 0; idx < FMT_NUMBER_OF_FORMATS; idx++)
         if (strlen (formats[idx].name) == ep - sp
-            && memcmp (formats[idx].name, sp, ep - sp))
+            && !memcmp (formats[idx].name, sp, ep - sp))
           break;
 
       /* Check format. */
@@ -74,7 +74,7 @@ parse_format_specifier_name (const char **cp, int allow_xt)
         {
           /* No match. */
           msg (SE, _("%.*s is not a valid data format."),
-               (int) (ep - sp), ds_value (&tokstr));
+               (int) (ep - sp), ds_c_str (&tokstr));
           idx = -1; 
         }
     }
@@ -84,8 +84,13 @@ parse_format_specifier_name (const char **cp, int allow_xt)
       idx = -1;
     }
       
-  if (cp != NULL)
-    *cp = ep;
+  if (cp != NULL) 
+    {
+      if (idx != -1)
+        *cp = ep;
+      else
+        *cp = NULL;
+    }
 
   return idx;
 }
@@ -333,7 +338,7 @@ parse_format_specifier (struct fmt_spec *input, int allow_xt)
   if (cp2 == cp && type != FMT_X)
     {
       msg (SE, _("Data format %s does not specify a width."),
-          ds_value (&tokstr));
+          ds_c_str (&tokstr));
       return 0;
     }
 
@@ -349,7 +354,7 @@ parse_format_specifier (struct fmt_spec *input, int allow_xt)
 
   if (*cp)
     {
-      msg (SE, _("Data format %s is not valid."), ds_value (&tokstr));
+      msg (SE, _("Data format %s is not valid."), ds_c_str (&tokstr));
       return 0;
     }
   lex_get ();