ONEWAY: Fix use of stack-allocated variable outside its scope.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 26 Nov 2018 01:47:45 +0000 (17:47 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 26 Nov 2018 01:47:45 +0000 (17:47 -0800)
The 'payload' object is a kind of class and should be allocated statically.

Found by Address Sanitizer.

src/language/stats/oneway.c

index cbc00e0fdd43a1e06ab0fef48316570888aeee13..da24cb6625837356891d5b389b439003a7b3bb6b 100644 (file)
@@ -711,11 +711,13 @@ run_oneway (const struct oneway_spec *cmd,
 
   for (v = 0; v < cmd->n_vars; ++v)
     {
-      struct payload payload;
-      payload.create = makeit;
-      payload.update = updateit;
-      payload.calculate = NULL;
-      payload.destroy = killit;
+      static const struct payload payload =
+        {
+          .create = makeit,
+          .update = updateit,
+          .calculate = NULL,
+          .destroy = killit
+        };
 
       ws.vws[v].iact = interaction_create (cmd->indep_var);
       ws.vws[v].cat = categoricals_create (&ws.vws[v].iact, 1, cmd->wv,