Fix several cases where lex_integer() or lex_number() could assert-fail.
[pspp] / src / language / stats / npar.c
index e277d36acccd887eee8687b925943634e0484a9e..d89eb0b876d63889f9a796b81b2a34f8daac3e29 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis. -*-c-*-
-   Copyright (C) 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2008, 2009, 2010, 2011, 2016 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
@@ -534,7 +534,7 @@ npar_execute (struct casereader *input,
       const struct npar_test *test = specs->test[t];
       if ( NULL == test->execute )
        {
-         msg (SW, _("NPAR subcommand not currently implemented."));
+         msg (SW, _("%s subcommand not currently implemented."), "NPAR");
          continue;
        }
       test->execute (ds, casereader_clone (input), specs->filter, test, specs->exact, specs->timer);
@@ -688,7 +688,7 @@ npar_runs (struct lexer *lexer, struct dataset *ds,
        }
       else
        {
-         lex_error (lexer, _("Expecting MEAN, MEDIAN, MODE or number"));
+         lex_error (lexer, _("Expecting %s, %s, %s or a number."), "MEAN", "MEDIAN", "MODE");
          return 0;
        }
                  
@@ -830,11 +830,11 @@ npar_chisquare (struct lexer *lexer, struct dataset *ds,
     {
       cstp->ranged = true;
       if ( ! lex_force_num (lexer)) return 0;
-      cstp->lo = lex_integer (lexer);
+      cstp->lo = lex_number (lexer);
       lex_get (lexer);
       lex_force_match (lexer, T_COMMA);
       if (! lex_force_num (lexer) ) return 0;
-      cstp->hi = lex_integer (lexer);
+      cstp->hi = lex_number (lexer);
       if ( cstp->lo >= cstp->hi )
        {
          msg (ME,
@@ -865,6 +865,8 @@ npar_chisquare (struct lexer *lexer, struct dataset *ds,
               if ( lex_match (lexer, T_ASTERISK))
                 {
                   n = f;
+                  if (!lex_force_num (lexer))
+                    return 0;
                   f = lex_number (lexer);
                   lex_get (lexer);
                 }
@@ -945,7 +947,8 @@ npar_binomial (struct lexer *lexer, struct dataset *ds,
        {
          if (lex_match (lexer, T_LPAREN))
            {
-             lex_force_num (lexer);
+             if (! lex_force_num (lexer))
+               return 2;
              btp->category1 = lex_number (lexer);
              lex_get (lexer);
              if ( lex_match (lexer, T_COMMA))
@@ -1080,7 +1083,7 @@ parse_two_sample_related_test (struct lexer *lexer,
   if (!parse_variables_const_pool (lexer, pool,
                                   dict,
                                   &vlist1, &n_vlist1,
-                                  PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
+                                  PV_NUMERIC | PV_NO_SCRATCH | PV_DUPLICATE) )
     return false;
 
   if ( lex_match (lexer, T_WITH))
@@ -1088,7 +1091,7 @@ parse_two_sample_related_test (struct lexer *lexer,
       with = true;
       if ( !parse_variables_const_pool (lexer, pool, dict,
                                        &vlist2, &n_vlist2,
-                                       PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
+                                       PV_NUMERIC | PV_NO_SCRATCH | PV_DUPLICATE) )
        return false;
 
       paired = (lex_match (lexer, T_LPAREN) &&
@@ -1101,9 +1104,12 @@ parse_two_sample_related_test (struct lexer *lexer,
       if (paired)
        {
          if ( n_vlist1 != n_vlist2)
-           msg (SE, _("PAIRED was specified but the number of variables "
+            {
+             msg (SE, _("PAIRED was specified but the number of variables "
                       "preceding WITH (%zu) did not match the number "
                       "following (%zu)."), n_vlist1, n_vlist2);
+              return false;
+            }
 
          test_parameters->n_pairs = n_vlist1 ;
        }
@@ -1270,9 +1276,8 @@ npar_median (struct lexer *lexer,
 
   mt->median = SYSMIS;
 
-  if ( lex_match (lexer, T_LPAREN))
+  if ( lex_match (lexer, T_LPAREN) && lex_force_num (lexer))
     {
-      lex_force_num (lexer);
       mt->median = lex_number (lexer);
       lex_get (lexer);
       lex_force_match (lexer, T_RPAREN);