Fix layout if functions include blocks before entry
authorChristoph Egger <christoph@christoph-egger.org>
Sat, 10 Jan 2015 16:43:04 +0000 (17:43 +0100)
committerChristoph Egger <christoph@christoph-egger.org>
Sat, 10 Jan 2015 16:43:04 +0000 (17:43 +0100)
If a function contained a block with a lower address than it's entry a
integer overflow occured resulting in bad layout. Handled now
correctly.

src/gui/Mainwindow.cxx

index 5643beb23731e7017f0b39b6066297fc05cdac92..196db38a18b838923a3cc3403b2b6b7d6c8768d0 100644 (file)
@@ -88,8 +88,14 @@ void Mainwindow::addFunction(Function* fun) {
        Disassembler * dis = manager->getDisassembler();
        BasicBlock * block = dis->getBasicBlock(fun->getStartAddress());
 
+       uint64_t start_address(std::numeric_limits<uint64_t>::max());
+       for (auto b : fun->blocks()) {
+               if (b.first < start_address)
+                       start_address = b.first;
+       }
+
        local__add_basic_block(block, manager->getDisassembler(), blocks, scene,
-                              block->getStartAddress(), 100);
+                              start_address, 100);
 
        QGraphicsView * view = new QGraphicsView(scene);
        w->addTab(view, "CFG");