Fixed use-after-free dict<> usage pattern in hierarchy.cc
authorClifford Wolf <clifford@clifford.at>
Tue, 16 Aug 2016 07:07:13 +0000 (09:07 +0200)
committerClifford Wolf <clifford@clifford.at>
Tue, 16 Aug 2016 07:07:13 +0000 (09:07 +0200)
passes/hierarchy/hierarchy.cc

index 92fcb7d40a855cec0b056109ade5ddb3d39fc7bb..4bb765e75138e4e335221f6fc8169f3c49cb4f84 100644 (file)
@@ -322,10 +322,12 @@ bool set_keep_assert(std::map<RTLIL::Module*, bool> &cache, RTLIL::Module *mod)
 int find_top_mod_score(Design *design, Module *module, dict<Module*, int> &db)
 {
        if (db.count(module) == 0) {
+               int score = 0;
                db[module] = 0;
                for (auto cell : module->cells())
                        if (design->module(cell->type))
-                               db[module] = max(db[module], find_top_mod_score(design, design->module(cell->type), db) + 1);
+                               score = max(score, find_top_mod_score(design, design->module(cell->type), db) + 1);
+               db[module] = score;
        }
        return db.at(module);
 }