DESCRIPTIVES: Fix a bug where the parser could enter an infinite loop
[pspp] / src / language / stats / descriptives.c
index beb5ec0b4182bd4fd48eef0f610f29b4d34129ce..7182049a6668850f02ffc28c08c9f1d58cf7773e 100644 (file)
@@ -284,7 +284,15 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds)
               else if (lex_match_id (lexer, "DEFAULT"))
                 dsc->show_stats |= DEFAULT_STATS;
               else
-               dsc->show_stats |= 1ul << (match_statistic (lexer));
+               {
+                 enum dsc_statistic s = match_statistic (lexer);
+                 if (s == DSC_NONE )
+                   {
+                     lex_error (lexer, NULL);
+                     goto error;
+                   }
+                 dsc->show_stats |= 1ul << s;
+               }
               lex_match (lexer, T_COMMA);
             }
           if (dsc->show_stats == 0)
@@ -309,7 +317,8 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds)
                 dsc->sort_ascending = 0;
               else
                 lex_error (lexer, NULL);
-              lex_force_match (lexer, T_RPAREN);
+              if (! lex_force_match (lexer, T_RPAREN))
+               goto error;
             }
         }
       else if (var_cnt == 0)
@@ -1044,7 +1053,7 @@ display (struct dsc_proc *dsc)
 
       for (j = 0; j < DSC_N_STATS; j++)
        if (dsc->show_stats & (1ul << j))
-         tab_double (t, nc++, i + 1, TAB_NONE, dv->stats[j], NULL);
+         tab_double (t, nc++, i + 1, TAB_NONE, dv->stats[j], NULL, RC_OTHER);
     }
 
   tab_title (t, _("Valid cases = %.*g; cases with missing value(s) = %.*g."),