Ghidra is a software reverse engineering (SRE) framework
GP-1 Corrected treatment of BadDataType within DataTypeManagerDB
ghidra1f250cfeac428
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeManagerDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeManagerDB.javaindex 45237bfb99..2bcc471309 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeManagerDB.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/data/DataTypeManagerDB.java@@ -158,6 +158,7 @@ abstract public class DataTypeManagerDB implements DataTypeManager {private LinkedList<Long> idsToDelete = new LinkedList<>();private LinkedList<Pair<DataType, DataType>> typesToReplace = new LinkedList<>();private List<DataType> favoritesList = new ArrayList<>();+ private BadDataType myBadDataType = new BadDataType(this);/*** Set of {@link AbstractIntegerDataType} IDs whose removal has been blocked@@ -1238,6 +1239,12 @@ abstract public class DataTypeManagerDB implements DataTypeManager {return dataType;}+ if (dataType instanceof BadDataType) {+ // Avoid adding BAD data type to the manager which+ // will appear when needed for a missing datatype+ return myBadDataType;+ }+if (dataType instanceof BitFieldDataType) {return resolveBitFieldDataType((BitFieldDataType) dataType, handler);}@@ -1888,10 +1895,13 @@ abstract public class DataTypeManagerDB implements DataTypeManager {throw new IllegalArgumentException("Datatype replacment with dynamic or factory type not permitted.");}- if (getID(existingDt) < 0) {+ if (!contains(existingDt)) {throw new IllegalArgumentException("Datatype to replace is not contained in this datatype manager.");}+ if (existingDt instanceof BadDataType) {+ throw new IllegalArgumentException("BAD Datatype can be deleted but not replaced.");+ }boolean fixupName = false;if (!contains(replacementDt)) {replacementDt = replacementDt.clone(this);@@ -2291,7 +2301,7 @@ abstract public class DataTypeManagerDB implements DataTypeManager {return DataType.DEFAULT;}if (dataTypeID == BAD_DATATYPE_ID) {- return BadDataType.dataType;+ return myBadDataType;}return getDataType(dataTypeID, null);}@@ -2343,6 +2353,12 @@ abstract public class DataTypeManagerDB implements DataTypeManager {return false;}+ if (dataType instanceof BadDataType) {+ // Cannot really replace BAD datatype which is generally not directly referenced+ deleteDataType(BAD_DATATYPE_ID);+ return true;+ }+long id = getID(dataType);if (id <= 0) { // removal of certain special types not permittedreturn false;@@ -4582,7 +4598,8 @@ abstract public class DataTypeManagerDB implements DataTypeManager {}}- private record DedupedConflicts(int processCnt, int replaceCnt) {}+ private record DedupedConflicts(int processCnt, int replaceCnt) {+ }private DedupedConflicts doDedupeConflicts(DataType dataType) {