opt_ffinv: Fix use after free.
authorMarcelina Kościelnicka <mwk@0x04.net>
Mon, 13 Jun 2022 10:22:59 +0000 (12:22 +0200)
committerMarcelina Kościelnicka <mwk@0x04.net>
Mon, 13 Jun 2022 12:04:04 +0000 (14:04 +0200)
passes/opt/opt_ffinv.cc

index fe5b59fa5c6401b1b9a331a9730f17c2258836f1..5d989dafdc0a97e59c2c9a423703b1c49dc4ec03 100644 (file)
@@ -201,10 +201,13 @@ struct OptFfInvWorker
        {
                log("Discovering LUTs.\n");
 
-               for (Cell *cell : module->selected_cells()) {
-                       if (!RTLIL::builtin_ff_cell_types().count(cell->type))
-                               continue;
+               std::vector<Cell *> ffs;
+
+               for (Cell *cell : module->selected_cells())
+                       if (RTLIL::builtin_ff_cell_types().count(cell->type))
+                               ffs.push_back(cell);
 
+               for (Cell *cell : ffs) {
                        FfData ff(&initvals, cell);
                        if (ff.has_sr)
                                continue;