CROSSTABS: Fix corner case in integer mode.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 2 Apr 2016 18:09:15 +0000 (11:09 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 2 Apr 2016 18:10:49 +0000 (11:10 -0700)
I'm not really sure what I was thinking when I wrote this code, but the
off-by-one errors could cause a crash.

Thanks to John Darrington for reporting the problem.

Bug #47600.

src/language/stats/crosstabs.q
tests/language/stats/crosstabs.at

index c9827396e2534d9cdebfe7a38cf72e2c5e4d8370..7b0c6c345e5e4a1dae7a27160c9030979ba2cabe 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2013, 2014, 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
@@ -514,7 +514,7 @@ crs_custom_variables (struct lexer *lexer, struct dataset *ds,
 
           vr->var = var;
           vr->min = min;
-         vr->max = max + 1.;
+         vr->max = max;
          vr->count = max - min + 1;
           hmap_insert (&proc->var_ranges, &vr->hmap_node,
                        hash_pointer (var, 0));
@@ -567,7 +567,7 @@ should_tabulate_case (const struct pivot_table *pt, const struct ccase *c,
       if (range != NULL)
         {
           double num = case_num (c, var);
-          if (num < range->min || num > range->max)
+          if (num < range->min || num >= range->max + 1.)
             return false;
         }
     }
index 559a13355ff970323782a52e692c643ebf905454..f7fccb434df5675d70a0eb7a1844ef3139b36c4d 100644 (file)
@@ -37,6 +37,32 @@ Total,.00,.00,.00,.00,1.00,.00,.00,1.00
 ]])
 AT_CLEANUP
 
+# Bug #47600.
+AT_SETUP([CROSSTABS integer mode crash 2])
+AT_DATA([crosstabs.sps], [dnl
+DATA LIST lIST /x y.
+BEGIN DATA.
+4 5
+END DATA.
+
+CROSSTABS
+        VARIABLES x (1,3) y (1,7)
+      /TABLES x BY y.
+])
+AT_CHECK([pspp -O format=csv crosstabs.sps], [0],
+  [[Table: Reading free-form data from INLINE.
+Variable,Format
+x,F8.0
+y,F8.0
+
+Table: Summary.
+,Cases,,,,,
+,Valid,,Missing,,Total,
+,N,Percent,N,Percent,N,Percent
+x * y,0,0.0%,1,100.0%,1,100.0%
+]])
+AT_CLEANUP
+
 # Bug #22037.
 AT_SETUP([CROSSTABS long string crash])
 AT_DATA([crosstabs.sps],