GP-1 Corrected treatment of BadDataType within DataTypeManagerDB

This commit is contained in:
ghidra1 2025-07-09 18:55:27 -04:00
parent 413949b64a
commit f250cfeac4

View file

@ -158,6 +158,7 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
private LinkedList<Long> idsToDelete = new LinkedList<>(); private LinkedList<Long> idsToDelete = new LinkedList<>();
private LinkedList<Pair<DataType, DataType>> typesToReplace = new LinkedList<>(); private LinkedList<Pair<DataType, DataType>> typesToReplace = new LinkedList<>();
private List<DataType> favoritesList = new ArrayList<>(); private List<DataType> favoritesList = new ArrayList<>();
private BadDataType myBadDataType = new BadDataType(this);
/** /**
* Set of {@link AbstractIntegerDataType} IDs whose removal has been blocked * Set of {@link AbstractIntegerDataType} IDs whose removal has been blocked
@ -1238,6 +1239,12 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
return dataType; 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) { if (dataType instanceof BitFieldDataType) {
return resolveBitFieldDataType((BitFieldDataType) dataType, handler); return resolveBitFieldDataType((BitFieldDataType) dataType, handler);
} }
@ -1888,10 +1895,13 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Datatype replacment with dynamic or factory type not permitted."); "Datatype replacment with dynamic or factory type not permitted.");
} }
if (getID(existingDt) < 0) { if (!contains(existingDt)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Datatype to replace is not contained in this datatype manager."); "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; boolean fixupName = false;
if (!contains(replacementDt)) { if (!contains(replacementDt)) {
replacementDt = replacementDt.clone(this); replacementDt = replacementDt.clone(this);
@ -2291,7 +2301,7 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
return DataType.DEFAULT; return DataType.DEFAULT;
} }
if (dataTypeID == BAD_DATATYPE_ID) { if (dataTypeID == BAD_DATATYPE_ID) {
return BadDataType.dataType; return myBadDataType;
} }
return getDataType(dataTypeID, null); return getDataType(dataTypeID, null);
} }
@ -2343,6 +2353,12 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
return false; 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); long id = getID(dataType);
if (id <= 0) { // removal of certain special types not permitted if (id <= 0) { // removal of certain special types not permitted
return false; return 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) { private DedupedConflicts doDedupeConflicts(DataType dataType) {