From: Ben Pfaff Date: Sat, 24 Feb 2024 18:50:02 +0000 (-0800) Subject: CTABLES: Fix crash with single nesting level, no label, and moving labels. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=928c1d754cfab8997d7533c8cb26440334af31e1;p=pspp CTABLES: Fix crash with single nesting level, no label, and moving labels. This fixes a crash for the following input: DATA LIST LIST NOTABLE /year (F4.0). BEGIN DATA 2020 2021 2022 2020 2020 END DATA. CTABLES /VLABELS VARIABLES=year DISPLAY=NONE /TABLE year [C] /CLABELS ROWLABELS=OPPOSITE. Thanks to Frans Houweling for reporting this bug and providing the test case. --- diff --git a/src/language/commands/ctables.c b/src/language/commands/ctables.c index 0d425ce8c2..3e70b32c69 100644 --- a/src/language/commands/ctables.c +++ b/src/language/commands/ctables.c @@ -4699,7 +4699,15 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t) for (size_t k = 0; k < nest->n; k++) { enum ctables_vlabel vlabel = ct->vlabels[var_get_dict_index (nest->vars[k])]; - if (vlabel == CTVL_NONE && nest->scale_idx == k) + if (vlabel == CTVL_NONE + && (nest->scale_idx == k + || ( + /* There's a single nesting level on this axis and the + labels are moved to a different axis. We need to + have something to stick into the dimension. It's + hard to see what that should be, so just force a + variable name to be shown. */ + nest->n == 1 && t->label_axis[a] != a))) vlabel = CTVL_NAME; if (vlabel != CTVL_NONE) { diff --git a/tests/language/commands/ctables.at b/tests/language/commands/ctables.at index 4aa8193102..b71695f759 100644 --- a/tests/language/commands/ctables.at +++ b/tests/language/commands/ctables.at @@ -2492,6 +2492,179 @@ Female ]) AT_CLEANUP +dnl When an axis is not nested, the (single) variable on that axis is moved +dnl to a different axis, and the variable is marked as DISPLAY=NONE, then +dnl PSPP crashed previously. This checks against regression for that crash. +AT_SETUP([CTABLES CLABELS with VLABELS DISPLAY=NONE]) +AT_CHECK([ln -s $top_srcdir/tests/language/commands/nhtsa.sav . || cp $top_srcdir/tests/language/commands/nhtsa.sav .]) +AT_DATA([ctables.sps], +[[GET 'nhtsa.sav'. +CTABLES /VLABELS VARIABLES=ALL DISPLAY=NONE /TABLE AgeGroup BY qns3a. +CTABLES /VLABELS VARIABLES=ALL DISPLAY=NONE /TABLE AgeGroup BY qns3a /CLABELS ROWLABELS=OPPOSITE. +CTABLES /VLABELS VARIABLES=ALL DISPLAY=NONE /TABLE AgeGroup BY qns3a /CLABELS COLLABELS=OPPOSITE. +CTABLES /VLABELS VARIABLES=ALL DISPLAY=NONE /TABLE AgeGroup BY qns3a /CLABELS ROWLABELS=LAYER. +CTABLES /VLABELS VARIABLES=ALL DISPLAY=NONE /TABLE AgeGroup BY qns3a /CLABELS COLLABELS=LAYER. +]]) +AT_CHECK([pspp ctables.sps --table-look="$builddir"/all-layers.stt -O box=unicode -O width=120], [0], [dnl + Custom Tables +╭─────────────┬─────┬──────╮ +│ │ Male│Female│ +│ ├─────┼──────┤ +│ │Count│ Count│ +├─────────────┼─────┼──────┤ +│15 or younger│ 0│ 0│ +│16 to 25 │ 594│ 505│ +│26 to 35 │ 476│ 491│ +│36 to 45 │ 489│ 548│ +│46 to 55 │ 526│ 649│ +│56 to 65 │ 516│ 731│ +│66 or older │ 531│ 943│ +╰─────────────┴─────┴──────╯ + + Custom Tables +╭────────┬──────────────────────────────────────────────────────┬──────────────────────────────────────────────────────╮ +│ │ Male │ Female │ +│ ├─────────┬───────┬──────┬──────┬──────┬───────┬───────┼─────────┬───────┬──────┬──────┬──────┬───────┬───────┤ +│ │ 15 or │ 16 to │ 26 to│ 36 to│ 46 to│ 56 to │ 66 or │ 15 or │ 16 to │ 26 to│ 36 to│ 46 to│ 56 to │ 66 or │ +│ │ younger │ 25 │ 35 │ 45 │ 55 │ 65 │ older │ younger │ 25 │ 35 │ 45 │ 55 │ 65 │ older │ +│ ├─────────┼───────┼──────┼──────┼──────┼───────┼───────┼─────────┼───────┼──────┼──────┼──────┼───────┼───────┤ +│ │ Count │ Count │ Count│ Count│ Count│ Count │ Count │ Count │ Count │ Count│ Count│ Count│ Count │ Count │ +├────────┼─────────┼───────┼──────┼──────┼──────┼───────┼───────┼─────────┼───────┼──────┼──────┼──────┼───────┼───────┤ +│agegroup│ 0│ 594│ 476│ 489│ 526│ 516│ 531│ 0│ 505│ 491│ 548│ 649│ 731│ 943│ +╰────────┴─────────┴───────┴──────┴──────┴──────┴───────┴───────┴─────────┴───────┴──────┴──────┴──────┴───────┴───────╯ + + Custom Tables +╭────────────────────┬─────╮ +│ │QNS3A│ +│ ├─────┤ +│ │Count│ +├────────────────────┼─────┤ +│15 or younger Male │ 0│ +│ Female│ 0│ +├────────────────────┼─────┤ +│16 to 25 Male │ 594│ +│ Female│ 505│ +├────────────────────┼─────┤ +│26 to 35 Male │ 476│ +│ Female│ 491│ +├────────────────────┼─────┤ +│36 to 45 Male │ 489│ +│ Female│ 548│ +├────────────────────┼─────┤ +│46 to 55 Male │ 526│ +│ Female│ 649│ +├────────────────────┼─────┤ +│56 to 65 Male │ 516│ +│ Female│ 731│ +├────────────────────┼─────┤ +│66 or older Male │ 531│ +│ Female│ 943│ +╰────────────────────┴─────╯ + + Custom Tables +15 or younger +╭────────┬─────┬──────╮ +│ │ Male│Female│ +│ ├─────┼──────┤ +│ │Count│ Count│ +├────────┼─────┼──────┤ +│agegroup│ 0│ 0│ +╰────────┴─────┴──────╯ + + Custom Tables +16 to 25 +╭────────┬─────┬──────╮ +│ │ Male│Female│ +│ ├─────┼──────┤ +│ │Count│ Count│ +├────────┼─────┼──────┤ +│agegroup│ 594│ 505│ +╰────────┴─────┴──────╯ + + Custom Tables +26 to 35 +╭────────┬─────┬──────╮ +│ │ Male│Female│ +│ ├─────┼──────┤ +│ │Count│ Count│ +├────────┼─────┼──────┤ +│agegroup│ 476│ 491│ +╰────────┴─────┴──────╯ + + Custom Tables +36 to 45 +╭────────┬─────┬──────╮ +│ │ Male│Female│ +│ ├─────┼──────┤ +│ │Count│ Count│ +├────────┼─────┼──────┤ +│agegroup│ 489│ 548│ +╰────────┴─────┴──────╯ + + Custom Tables +46 to 55 +╭────────┬─────┬──────╮ +│ │ Male│Female│ +│ ├─────┼──────┤ +│ │Count│ Count│ +├────────┼─────┼──────┤ +│agegroup│ 526│ 649│ +╰────────┴─────┴──────╯ + + Custom Tables +56 to 65 +╭────────┬─────┬──────╮ +│ │ Male│Female│ +│ ├─────┼──────┤ +│ │Count│ Count│ +├────────┼─────┼──────┤ +│agegroup│ 516│ 731│ +╰────────┴─────┴──────╯ + + Custom Tables +66 or older +╭────────┬─────┬──────╮ +│ │ Male│Female│ +│ ├─────┼──────┤ +│ │Count│ Count│ +├────────┼─────┼──────┤ +│agegroup│ 531│ 943│ +╰────────┴─────┴──────╯ + + Custom Tables +Male +╭─────────────┬─────╮ +│ │QNS3A│ +│ ├─────┤ +│ │Count│ +├─────────────┼─────┤ +│15 or younger│ 0│ +│16 to 25 │ 594│ +│26 to 35 │ 476│ +│36 to 45 │ 489│ +│46 to 55 │ 526│ +│56 to 65 │ 516│ +│66 or older │ 531│ +╰─────────────┴─────╯ + + Custom Tables +Female +╭─────────────┬─────╮ +│ │QNS3A│ +│ ├─────┤ +│ │Count│ +├─────────────┼─────┤ +│15 or younger│ 0│ +│16 to 25 │ 505│ +│26 to 35 │ 491│ +│36 to 45 │ 548│ +│46 to 55 │ 649│ +│56 to 65 │ 731│ +│66 or older │ 943│ +╰─────────────┴─────╯ +]) +AT_CLEANUP + AT_SETUP([CTABLES missing values]) AT_DATA([ctables.sps], [[DATA LIST LIST NOTABLE/x y.