Skip to content

Commit 2d19520

Browse files
committed
GP-5583 Code review minor changes
1 parent 65409da commit 2d19520

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

Ghidra/Features/Decompiler/src/main/java/ghidra/app/cmd/function/DecompilerSwitchAnalysisCmd.java

+22-22
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public class DecompilerSwitchAnalysisCmd extends BackgroundCommand<Program> {
4848
protected DecompInterface decompiler;
4949
private boolean useArraysForSwitchTables = false;
5050

51-
public DecompilerSwitchAnalysisCmd(DecompileResults decopmileResults) {
52-
this.decompilerResults = decopmileResults;
51+
public DecompilerSwitchAnalysisCmd(DecompileResults decompileResults) {
52+
this.decompilerResults = decompileResults;
5353
}
5454

5555
@Override
@@ -71,20 +71,18 @@ private void analyzeFunction(TaskMonitor monitor) {
7171
}
7272

7373
try {
74-
7574
monitor.checkCancelled();
7675

7776
Function f = decompilerResults.getFunction();
7877
HighFunction hfunction = decompilerResults.getHighFunction();
79-
processBranchIND(f, hfunction, monitor);
80-
81-
monitor.checkCancelled();
82-
78+
8379
String errMsg = getStatusMsg();
84-
if (decompilerResults.getHighFunction() == null) {
80+
if (hfunction == null) {
8581
String msg = (errMsg != null && errMsg.length() != 0) ? (": " + errMsg) : "";
8682
Msg.debug(this, " Failed to decompile function: " + f.getName() + msg);
8783
}
84+
85+
processBranchIND(f, hfunction, monitor);
8886
}
8987
catch (Exception e) {
9088
if (!monitor.isCancelled()) {
@@ -248,35 +246,37 @@ public boolean hasAllReferences(TaskMonitor monitor, JumpTable table, Instructio
248246
Address[] tableDest = table.getCases();
249247
Integer[] caseValues = table.getLabelValues();
250248

251-
boolean allRefsFound = true;
252-
int caseIndex;
253-
for (caseIndex = 0; caseIndex < tableDest.length; caseIndex++) {
249+
// check that all cases are already a reference on the instruction, except default
250+
for (int caseIndex = 0; caseIndex < tableDest.length; caseIndex++) {
254251
monitor.checkCancelled();
255252

256253
// a case is default if it is first case to not have a value, or has a magic case value
257254
boolean isDefaultCase = isDefaultCase(caseValues, caseIndex);
258255

259-
boolean foundit = false;
260256
if (containingBody != null && !containingBody.contains(tableDest[caseIndex])) {
261257
// switch case missing from owner function's body
262-
allRefsFound = false;
263-
break;
258+
return false;
264259
}
260+
261+
boolean foundit = false;
265262
for (Reference element : referencesFrom) {
266263
if (element.getToAddress().equals(tableDest[caseIndex])) {
267-
// good only if this isn't default case
268-
// default case should not be on switching instruction
269-
foundit = !isDefaultCase;
264+
foundit = true;
270265
break;
271-
} else if (isDefaultCase) {
272-
foundit = true; // not finding default case is good
273266
}
274267
}
275-
if (!foundit) {
276-
allRefsFound = false;
268+
if (isDefaultCase) {
269+
// default case should not be on switching instruction
270+
if (foundit) {
271+
return false;
272+
}
273+
}
274+
else if (!foundit) {
275+
return false;
277276
}
278277
}
279-
return allRefsFound;
278+
279+
return true;
280280
}
281281

282282
/*

0 commit comments

Comments
 (0)