From: Ben Pfaff Date: Sat, 30 Sep 2023 20:19:21 +0000 (-0700) Subject: MATCH FILES: Fix crash in string variable resizing. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53a4da1f0627ebcb0a63d914a2e65fc42b949ba3;p=pspp MATCH FILES: Fix crash in string variable resizing. Commmit 638bf380e550 ("combine-files: Allow matching string variables to have different widths.") introduced a bug in the case where the variables in data files being combined didn't have the same variable order. This is kind of an embarrassing bug since the input files having the same order of variables is an exceptional case anyhow. This commit should fix the problem. The test as updated will crash if the bug regresses. Thanks to Frans Houweling for reporting the bug. --- diff --git a/src/language/commands/combine-files.c b/src/language/commands/combine-files.c index a6441de97e..dd70e3742d 100644 --- a/src/language/commands/combine-files.c +++ b/src/language/commands/combine-files.c @@ -317,13 +317,17 @@ combine_files (enum comb_command_type command, { r = xmalloc (sizeof *r); *r = (struct comb_resizer) { - .output_proto = caseproto_ref (dict_get_proto (proc.dict)), + .output_proto = caseproto_ref (dict_get_proto (cf->dict)), .indexes = xnmalloc (dict_get_n_vars (cf->dict), sizeof *r->indexes), }; cf->resizer = r; } - r->indexes[r->n_indexes++] = var_get_dict_index (dv); + + size_t dict_index = var_get_dict_index (dv); + r->output_proto = caseproto_set_width (r->output_proto, + dict_index, mw); + r->indexes[r->n_indexes++] = dict_index; } } } diff --git a/tests/language/commands/match-files.at b/tests/language/commands/match-files.at index 3341ce79f1..55c70816c3 100644 --- a/tests/language/commands/match-files.at +++ b/tests/language/commands/match-files.at @@ -217,11 +217,11 @@ AT_CLEANUP AT_SETUP([MATCH FILES with different string widths]) AT_DATA([match-files.sps], [dnl -DATA LIST LIST NOTABLE/name (A6) x. +DATA LIST LIST NOTABLE/x (F8.2) name (A6). BEGIN DATA. -al,7 -brad,8 -carl,9 +7,al +8,brad +9,carl END DATA. SAVE OUTFILE='x.sav'. @@ -231,8 +231,8 @@ al,1 carl,2 dan,3 END DATA. -MATCH FILES/FILE='x.sav'/FILE=*/BY name. -LIST. +MATCH FILES/FILE=*/FILE='x.sav'/BY name. +LIST/name x y. ]) AT_CHECK([pspp -O format=csv match-files.sps], [0], [dnl Table: Data List