Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/GP-2079_RelativePointerCompare'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmkurtz committed Jun 10, 2022
2 parents 6676667 + 36a1a33 commit 91f44ba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,26 @@ void TypePointerRel::printRaw(ostream &s) const
s << ']';
}

int4 TypePointerRel::compare(const Datatype &op,int4 level) const

{
int4 res = TypePointer::compare(op,level); // Compare as plain pointers first
if (res != 0) return res;
// Both must be relative pointers
TypePointerRel *tp = (TypePointerRel *) &op;
// Its possible a formal relative pointer gets compared to its equivalent ephemeral version.
// In which case, we prefer the formal version.
if (stripped == (TypePointer *)0) {
if (tp->stripped != (TypePointer *)0)
return -1;
}
else {
if (tp->stripped == (TypePointer *)0)
return 1;
}
return 0;
}

int4 TypePointerRel::compareDependency(const Datatype &op) const

{
Expand Down
1 change: 1 addition & 0 deletions Ghidra/Features/Decompiler/src/decompile/cpp/type.hh
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ public:
/// \return the offset value in \e address \e units
int4 getPointerOffset(void) const { return AddrSpace::byteToAddressInt(offset, wordsize); }
virtual void printRaw(ostream &s) const;
virtual int4 compare(const Datatype &op,int4 level) const;
virtual int4 compareDependency(const Datatype &op) const;
virtual Datatype *clone(void) const { return new TypePointerRel(*this); }
virtual void saveXml(ostream &s) const;
Expand Down

0 comments on commit 91f44ba

Please sign in to comment.