Add test for PERMISSIONS with bad syntax
authorJohn Darrington <john@darrington.wattle.id.au>
Tue, 5 Apr 2016 18:01:35 +0000 (20:01 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 5 Apr 2016 18:01:35 +0000 (20:01 +0200)
src/language/lexer/lexer.c
src/language/utilities/permissions.c
tests/language/utilities/permissions.at

index 1f455119f00b1779f51787d54dedf4b469c46b1b..08d35d8c00312d98d2baeb7e80ff04141037b9f9 100644 (file)
@@ -604,9 +604,16 @@ lex_force_match (struct lexer *lexer, enum token_type type)
     }
   else
     {
-      char *s = xasprintf ("`%s'", token_type_to_string (type));
-      lex_error_expecting (lexer, s, NULL_SENTINEL);
-      free (s);
+      const char *type_string = token_type_to_string (type);
+      if (type_string)
+       {
+         char *s = xasprintf ("`%s'", type_string);
+         lex_error_expecting (lexer, s, NULL_SENTINEL);
+         free (s);
+       }
+      else
+       lex_error_expecting (lexer, token_type_to_name (type), NULL_SENTINEL);
+      
       return false;
     }
 }
index 904ba95b270e2a7de6c5a22e729f64b8b3247cf1..3f679c150e21968370c2b2d283fcdfb7145f4131 100644 (file)
@@ -51,9 +51,10 @@ cmd_permissions (struct lexer *lexer, struct dataset *ds UNUSED)
     lex_match (lexer, T_EQUALS);
 
   str = lex_tokcstr (lexer);
-  fn = strdup (str);
+  if (str)
+    fn = strdup (str);
 
-  if (!lex_force_match (lexer, T_STRING))
+  if (!lex_force_match (lexer, T_STRING) || str == NULL)
     goto error;
 
   lex_match (lexer, T_SLASH);
index 873057c85e2cb4c67ee0e3028942bd85b9037856..56698c337cadf61f8a6303a2f09d8fc93f44fea9 100644 (file)
@@ -23,3 +23,14 @@ AT_CHECK([ls -l foobar], [0], [stdout])
 AT_CHECK([sed 's/^\(..........\).*/\1/' stdout], [0], [-rw-r--r--
 ])
 AT_CLEANUP
+
+
+
+AT_SETUP([PERMISSIONS - bad syntax])
+AT_DATA([pe.sps], [[PERMI|SIONS /FILE='foobar' PERMISSIONS=WRITEABLE.
+]])
+
+AT_CHECK([pspp -O format=csv pe.sps], [1], [dnl
+pe.sps:1.6: error: PERMISSIONS: Syntax error at `|': expecting STRING.
+])
+AT_CLEANUP