Ghidra is a software reverse engineering (SRE) framework
GP-2082 Guarantee only a single switch edge is labeled default
caheckman987b524193b0
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/block.ccindex 985e3e97db..201595af16 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc@@ -301,6 +301,18 @@ void FlowBlock::setGotoBranch(int4 i)outofthis[i].point->flags |= f_interior_gotoin;}+/// The switch can have exactly 1 default edge, so we make sure other edges are not marked.+/// \param pos is the index of the \e out edge that should be the default+void FlowBlock::setDefaultSwitch(int4 pos)++{+ for(int4 i=0;i<outofthis.size();++i) {+ if (isDefaultBranch(i))+ clearOutEdgeFlag(i, f_defaultswitch_edge); // Clear any previous flag+ }+ setOutEdgeFlag(pos,f_defaultswitch_edge);+}+/// \b return \b true if block is the target of a jumpbool FlowBlock::isJumpTarget(void) constdiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/block.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/block.hhindex fbf626f8e4..b071e75b73 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/block.hh+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/block.hh@@ -190,7 +190,7 @@ public:void setVisitCount(int4 i) { visitcount = i; } ///< Set the number of times this block has been visitedint4 getVisitCount(void) const { return visitcount; } ///< Get the count of visitsvoid setGotoBranch(int4 i); ///< Mark a \e goto branch- void setDefaultSwitch(int4 i) { setOutEdgeFlag(i,f_defaultswitch_edge); } ///< Mark an edge as the switch default+ void setDefaultSwitch(int4 pos); ///< Mark an edge as the switch defaultbool isMark(void) const { return ((flags&f_mark)!=0); } ///< Return \b true if \b this block has been markedvoid setMark(void) { flags |= f_mark; } ///< Mark \b this blockvoid clearMark(void) { flags &= ~f_mark; } ///< Clear any mark on \b this block