From: Christoph Egger <christoph@christoph-egger.org>
Date: Sat, 10 Jan 2015 16:43:04 +0000 (+0100)
Subject: Fix layout if functions include blocks before entry
X-Git-Tag: v0.1~135
X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=f6f7e517e577a67f01256ca0b0edea83729849f4;p=frida%2Ffrida.git

Fix layout if functions include blocks before entry

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.
---

diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx
index 5643beb..196db38 100644
--- a/src/gui/Mainwindow.cxx
+++ b/src/gui/Mainwindow.cxx
@@ -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");