GP-1 Always use BadDataType.datatype instance

This commit is contained in:
ghidra1 2025-07-10 12:04:01 -04:00
parent 894e65589a
commit 8938cc3478
2 changed files with 9 additions and 21 deletions

View file

@ -158,7 +158,6 @@ 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
@ -1242,7 +1241,7 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
if (dataType instanceof BadDataType) { if (dataType instanceof BadDataType) {
// Avoid adding BAD data type to the manager which // Avoid adding BAD data type to the manager which
// will appear when needed for a missing datatype // will appear when needed for a missing datatype
return myBadDataType; return BadDataType.dataType;
} }
if (dataType instanceof BitFieldDataType) { if (dataType instanceof BitFieldDataType) {
@ -2301,7 +2300,7 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
return DataType.DEFAULT; return DataType.DEFAULT;
} }
if (dataTypeID == BAD_DATATYPE_ID) { if (dataTypeID == BAD_DATATYPE_ID) {
return myBadDataType; return BadDataType.dataType;
} }
return getDataType(dataTypeID, null); return getDataType(dataTypeID, null);
} }

View file

@ -17,26 +17,23 @@ package ghidra.program.model.data;
import ghidra.docking.settings.Settings; import ghidra.docking.settings.Settings;
import ghidra.program.model.mem.MemBuffer; import ghidra.program.model.mem.MemBuffer;
import ghidra.util.classfinder.ClassSearcher;
/** /**
* Provides an implementation of a data type that is not valid (bad) as it is used in * Provides an implementation of a data type that is not valid (bad) as it is used in
* the program. For example, the class for the underlying data type may no longer be * the program. For example, the class for the underlying data type may no longer be
* available or the data type may not fit where it has been placed in the program. * available or the data type may not fit where it has been placed in the program.
* <P>
* This field is not meant to be loaded by the {@link ClassSearcher}, hence the X in the name.
*/ */
public class BadDataType extends BuiltIn implements Dynamic { public class BadDataType extends BuiltIn implements Dynamic {
private final static long serialVersionUID = 1;
public static final BadDataType dataType = new BadDataType(); public static final BadDataType dataType = new BadDataType();
public BadDataType() { private BadDataType() {
this(null); super(CategoryPath.ROOT, "-BAD-", null);
} }
public BadDataType(DataTypeManager dtm) { @Override
super(null, "-BAD-", dtm); public DataType clone(DataTypeManager dtm) {
return this;
} }
/** /**
@ -89,14 +86,6 @@ public class BadDataType extends BuiltIn implements Dynamic {
return getDescription(); return getDescription();
} }
@Override
public DataType clone(DataTypeManager dtm) {
if (dtm == getDataTypeManager()) {
return this;
}
return new BadDataType(dtm);
}
@Override @Override
public boolean canSpecifyLength() { public boolean canSpecifyLength() {
return true; return true;