transformations: Fix memory error in trns_chain_prepend().
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 19 Apr 2024 00:27:12 +0000 (17:27 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 19 Apr 2024 00:27:12 +0000 (17:27 -0700)
This only worked if the transformation chain had one element.

Thanks to Zhou Geng for reporting this bug as poc30 in the report here:
https://lists.gnu.org/archive/html/bug-gnu-pspp/2024-03/msg00015.html

src/data/transformations.c

index fdb2cb84bd7f854bc3c16a8d32c3968e0ceceace..55067ea878847f54b57ee160a120b1fba575eb03 100644 (file)
@@ -61,7 +61,7 @@ trns_chain_prepend (struct trns_chain *chain, const struct transformation *t)
     chain->xforms = x2nrealloc (chain->xforms, &chain->allocated,
                                 sizeof *chain->xforms);
 
-  insert_element (chain->xforms, 1, sizeof *chain->xforms, 0);
+  insert_element (chain->xforms, chain->n, sizeof *chain->xforms, 0);
   chain->xforms[0] = *t;
   chain->n++;
 }