From: Ben Pfaff Date: Sat, 2 Apr 2016 18:09:15 +0000 (-0700) Subject: CROSSTABS: Fix corner case in integer mode. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a490863ee96cee59050ca70d3c22491e54a3ab8;p=pspp CROSSTABS: Fix corner case in integer mode. 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. --- diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index c9827396e2..7b0c6c345e 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -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; } } diff --git a/tests/language/stats/crosstabs.at b/tests/language/stats/crosstabs.at index 559a13355f..f7fccb434d 100644 --- a/tests/language/stats/crosstabs.at +++ b/tests/language/stats/crosstabs.at @@ -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],