RANK: Fix crash ranking multiple variables without any rank specs. 20130312030503/pspp 20130313030511/pspp 20130314030502/pspp 20130315030502/pspp 20130316030504/pspp
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 12 Mar 2013 05:08:34 +0000 (22:08 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 12 Mar 2013 05:08:34 +0000 (22:08 -0700)
Incidentally fixes a small memory leak in the same situation.

Bug #38482.
Reported by John Darrington.

src/language/stats/rank.c
tests/language/stats/rank.at

index 5f5591adb989fdd25b2c57bc7dc3a7239b4f0919..a29a3fd11f7870a746b1d26c06d8a63eaae96690 100644 (file)
@@ -784,8 +784,8 @@ cmd_rank (struct lexer *lexer, struct dataset *ds)
 
       rs = pool_calloc (rank.pool, 1, sizeof *rs);
       rs->rfunc = RANK;
-      rs->dest_names = pool_calloc (rank.pool, 1, sizeof *rs->dest_names);
-      rs->dest_labels = pool_calloc (rank.pool, 1, sizeof *rs->dest_labels);
+      rs->dest_names = pool_calloc (rank.pool, rank.n_vars,
+                                    sizeof *rs->dest_names);
 
       rank.rs = rs;
       rank.n_rs = 1;
index 45ca41aea016a0d30c050fda87327d46a3d1b2b3..f47d23e861cf04ce989750623c016f31908ca1dd 100644 (file)
@@ -37,6 +37,40 @@ x,Rx
 ])
 AT_CLEANUP
 
+# This checks for regression against a crash reported as bug #38482
+# that occurred when multiple variables were specified without any
+# rank specifications.
+AT_SETUP([RANK multiple variables with defaults])
+AT_DATA([rank.sps], [dnl
+DATA LIST LIST NOTABLE /x * y * z *.
+BEGIN DATA.
+    1.00     2.00     3.00
+    4.00     5.00     6.00
+END DATA.
+
+RANK ALL.
+
+LIST.
+])
+AT_CHECK([pspp -o pspp.csv rank.sps])
+AT_CHECK([cat pspp.csv], [0], [dnl
+Variables Created By RANK
+
+
+
+x into Rx(RANK of x)
+
+y into Ry(RANK of y)
+
+z into Rz(RANK of z)
+
+Table: Data List
+x,y,z,Rx,Ry,Rz
+1.00,2.00,3.00,1.000,1.000,1.000
+4.00,5.00,6.00,2.000,2.000,2.000
+])
+AT_CLEANUP
+
 AT_SETUP([RANK with RANK, RFRACTION, N])
 AT_DATA([rank.sps], [dnl
 DATA LIST LIST NOTABLE /a * b *.