Skip to content

Ghidra is a software reverse engineering (SRE) framework

Fix for CommentSorter crash

caheckman0df9575f1b45
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/comment.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/comment.cc
index a51afda059..9cc74071b6 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/comment.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/comment.cc
@@ -283,6 +283,8 @@ bool CommentSorter::findPosition(Subsort &subsort,Comment *comm,const Funcdata *
if (opiter != fd->endOpAll()) { // If there is an op at or after the comment
PcodeOp *op = (*opiter).second;
BlockBasic *block = op->getParent();
+ if (block == (BlockBasic *)0)
+ throw LowlevelError("Dead op reaching CommentSorter");
if (block->contains(comm->getAddr())) { // If the op's block contains the address
// Associate comment with this op
subsort.setBlock(block->getIndex(), (uint4)op->getSeqNum().getOrder());
@@ -295,6 +297,8 @@ bool CommentSorter::findPosition(Subsort &subsort,Comment *comm,const Funcdata *
--opiter;
PcodeOp *op = (*opiter).second;
BlockBasic *block = op->getParent();
+ if (block == (BlockBasic *)0)
+ throw LowlevelError("Dead op reaching CommentSorter");
if (block->contains(comm->getAddr())) { // If the op's block contains the address
// Treat the comment as being in this block at the very end
subsort.setBlock(block->getIndex(),0xffffffff);
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.cc
index f8fb03b541..8745d36852 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.cc
@@ -145,6 +145,7 @@ void Funcdata::stopProcessing(void)
{
flags |= processing_complete;
+ obank.destroyDead(); // Free up anything in the dead list
#ifdef CPUI_STATISTICS
glb->stats->process(*this);
#endif