From feeebee4b8d6a1e549e73f7015fe4ad491d9b785 Mon Sep 17 00:00:00 2001
From: clc5q <clc5q@git.zephyr-software.com>
Date: Thu, 28 Jan 2016 03:50:30 +0000
Subject: [PATCH] Detect corner cases of fixed-call pushes and jumps.

Former-commit-id: 7f9438be1b6f30b65e944974d3309f927d4fd625
---
 src/interfaces/irdb/STARS_IRDB_Function.cpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/interfaces/irdb/STARS_IRDB_Function.cpp b/src/interfaces/irdb/STARS_IRDB_Function.cpp
index 68ce462d..a1c15292 100644
--- a/src/interfaces/irdb/STARS_IRDB_Function.cpp
+++ b/src/interfaces/irdb/STARS_IRDB_Function.cpp
@@ -227,6 +227,7 @@ void STARS_IRDB_Function_t::FindFixedCalls(SMPFunction *CurrFunc) {
 
 	for (list<SMPInstr *>::iterator InstIter = CurrFunc->GetFirstInstIter(); InstIter != CurrFunc->GetLastInstIter(); ++InstIter) {
 		SMPInstr *CurrInst = (*InstIter);
+		STARS_ea_t InstAddr = CurrInst->GetAddr();
 		if (CurrInst->IsFixedCallPush()) {
 			FixedCallPushSeen = true;
 			STARSOpndTypePtr PushedOpnd = CurrInst->GetPushedOpnd();
@@ -236,12 +237,19 @@ void STARS_IRDB_Function_t::FindFixedCalls(SMPFunction *CurrFunc) {
 				if (success && (!TargetIDSet.empty())) {
 					assert(1 == TargetIDSet.size());
 					FixedCallPushTargetID = TargetIDSet.begin()->GetIDWithinFile();
-					if (!this->IsInstIDInFunc(FixedCallPushTargetID)) { // trying to find push of return address after fixed call
+					// trying to find push of return address after fixed call
+					//  Corner case: Call could be at end of func, so pushed ID could be outside
+					//  the func.
+#if 1
+					cout << "Found fixed call push at " << InstAddr << " to ID " << FixedCallPushTargetID << endl;
+#else
+					if (!this->IsInstIDInFunc(FixedCallPushTargetID)) { 
 						FixedCallPushTargetID = STARS_BADADDR;
 					}
 					else {
-						cout << "Found fixed call push at ID " << FixedCallPushTargetID << endl;
+						cout << "Found fixed call push at " << InstAddr << " to ID " << FixedCallPushTargetID << endl;
 					}
+#endif
 				}
 			}
 		}
-- 
GitLab