QUICK CLUSTER: Fix crash on negative parameters
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 30 Dec 2013 09:13:16 +0000 (10:13 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 30 Dec 2013 09:13:16 +0000 (10:13 +0100)
src/language/stats/quick-cluster.c
tests/language/stats/quick-cluster.at

index bc66cce795caf06932ed3da6269b306bd0a6cd52..946181b01a6b22e3061a4b26c961ed6f88236bd7 100644 (file)
@@ -548,6 +548,11 @@ cmd_quick_cluster (struct lexer *lexer, struct dataset *ds)
                    {
                      lex_force_int (lexer);
                      qc.ngroups = lex_integer (lexer);
+                     if (qc.ngroups <= 0)
+                       {
+                         lex_error (lexer, _("The number of clusters must be positive"));
+                         goto error;
+                       }
                      lex_get (lexer);
                      lex_force_match (lexer, T_RPAREN);
                    }
@@ -558,6 +563,11 @@ cmd_quick_cluster (struct lexer *lexer, struct dataset *ds)
                    {
                      lex_force_int (lexer);
                      qc.maxiter = lex_integer (lexer);
+                     if (qc.maxiter <= 0)
+                       {
+                         lex_error (lexer, _("The number of iterations must be positive"));
+                         goto error;
+                       }
                      lex_get (lexer);
                      lex_force_match (lexer, T_RPAREN);
                    }
index 9e3e87c899d3635b3e21e46852e48a5e11157691..495635b0b8dd1bbb274da18ae3671c946d629b21 100644 (file)
@@ -210,3 +210,22 @@ AT_CHECK([diff pspp-s.csv pspp-pw.csv], [0])
 
 
 AT_CLEANUP
+
+
+
+AT_SETUP([QUICK CLUSTER crash on bad cluster quantity])
+AT_DATA([badn.sps], [dnl
+data list notable list /x * y *.
+begin data.
+1   2
+1   2.2
+end data.
+
+QUICK CLUSTER x y 
+       /CRITERIA = CLUSTER(0)
+       .
+])
+
+AT_CHECK([pspp -O format=csv badn.sps], [1], [ignore])
+
+AT_CLEANUP
\ No newline at end of file