MATCH FILES: Fix crash in string variable resizing.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 30 Sep 2023 20:19:21 +0000 (13:19 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 30 Sep 2023 20:29:05 +0000 (13:29 -0700)
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.

src/language/commands/combine-files.c
tests/language/commands/match-files.at

index a6441de97eb5eb1b3a8e34c1d9230b93e361dbc5..dd70e3742d2af19857a932288b9a6a777fc797e9 100644 (file)
@@ -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;
             }
         }
     }
index 3341ce79f1c0909fd6b9a47e4d5a8c377d74e0fa..55c70816c378522d04efd6fd887d6dfaa96e0a1b 100644 (file)
@@ -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