q2c: Remove, since it is no longer used.
[pspp] / src / language / lexer / variable-parser.c
index 514ce160f41b2e7fc751ddb508fc89d05f26e9b4..e637940351af76439ea397dbf3c067cfddfef6a0 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012, 2020 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -123,7 +123,8 @@ parse_variable (struct lexer *lexer, const struct dictionary *d)
 /* Parses a set of variables from dictionary D given options
    OPTS.  Resulting list of variables stored in *VAR and the
    number of variables into *CNT.  Returns true only if
-   successful. */
+   successful.  The dictionary D must contain at least one
+   variable.  */
 bool
 parse_variables (struct lexer *lexer, const struct dictionary *d,
                        struct variable ***var,
@@ -137,6 +138,12 @@ parse_variables (struct lexer *lexer, const struct dictionary *d,
   assert (cnt != NULL);
 
   vs = var_set_create_from_dict (d);
+  if (var_set_get_cnt (vs) == 0)
+    {
+      *cnt = 0;
+      var_set_destroy (vs);
+      return false;
+    }
   success = parse_var_set_vars (lexer, vs, var, cnt, opts);
   var_set_destroy (vs);
   return success;
@@ -461,6 +468,7 @@ parse_DATA_LIST_vars (struct lexer *lexer, const struct dictionary *dict,
   struct stringi_set set;
 
   char *name1 = NULL;
+  char *name2 = NULL;
 
   bool ok = false;
 
@@ -504,7 +512,9 @@ parse_DATA_LIST_vars (struct lexer *lexer, const struct dictionary *dict,
           int root_len1, root_len2;
           unsigned long int number;
 
-          char *name2 = parse_DATA_LIST_var (lexer, dict);
+          name2 = parse_DATA_LIST_var (lexer, dict);
+          if (!name2)
+            goto exit;
 
           root_len1 = extract_numeric_suffix (name1, &num1, &n_digits1);
           if (root_len1 == 0)
@@ -541,6 +551,7 @@ parse_DATA_LIST_vars (struct lexer *lexer, const struct dictionary *dict,
           free (name1);
           name1 = NULL;
           free (name2);
+          name2 = NULL;
        }
       else
        {
@@ -575,6 +586,7 @@ exit:
       *n_varsp = 0;
 
       free (name1);
+      free (name2);
     }
   return ok;
 }
@@ -916,7 +928,7 @@ lex_match_variable (struct lexer *lexer, const struct dictionary *dict, const st
 
   *var = parse_variable_const  (lexer, dict);
 
-  if ( *var == NULL)
+  if (*var == NULL)
     return false;
   return true;
 }
@@ -952,12 +964,12 @@ parse_internal_interaction (struct lexer *lexer, const struct dictionary *dict,
 
   assert (v);
 
-  if ( *iact == NULL)
+  if (*iact == NULL)
     *iact = interaction_create (v);
   else
     interaction_add_variable (*iact, v);
 
-  if ( lex_match (lexer, T_ASTERISK) || lex_match (lexer, T_BY))
+  if (lex_match (lexer, T_ASTERISK) || lex_match (lexer, T_BY))
     {
       return parse_internal_interaction (lexer, dict, iact, iact);
     }