GP-5006 Address hash collisions in DataTypeSymbol

This commit is contained in:
caheckman 2024-10-09 17:16:58 +00:00
parent cb5ab633de
commit 5fa798429f

View file

@ -65,27 +65,30 @@ public class DataTypeSymbol {
} }
// Create the name and the category // Create the name and the category
CategoryPath path = new CategoryPath(category); CategoryPath path = new CategoryPath(category);
String hash = generateHash(datatype); int hash = generateHash(datatype);
String type_hashname = "dt_" + hash; for (int i = 0; i < 256; ++i) { // Try multiple slots
try { String hashString = Integer.toHexString(hash + i); // Slot near original hash
datatype.setNameAndCategory(path, type_hashname); String type_hashname = "dt_" + hashString;
} try {
catch (InvalidNameException e) { datatype.setNameAndCategory(path, type_hashname);
return null; }
} catch (InvalidNameException e) {
catch (DuplicateNameException e) { return null;
return null; }
} catch (DuplicateNameException e) {
DataType preexists = dtmanage.getDataType(path, type_hashname); return null;
if (preexists != null) { // Named datatype already exists }
DataType preexists = dtmanage.getDataType(path, type_hashname);
if (preexists == null) { // Found empty slot, store signature here
datatype = dtmanage.addDataType(datatype, DataTypeConflictHandler.KEEP_HANDLER);
return hashString;
}
if (preexists.isEquivalent(datatype)) { // If this is the right type if (preexists.isEquivalent(datatype)) { // If this is the right type
datatype = preexists; datatype = preexists;
return hash; // We are done return hashString; // We are done
} }
return null; // Otherwise we can't proceed
} }
datatype = dtmanage.addDataType(datatype, DataTypeConflictHandler.KEEP_HANDLER); return null;
return hash;
} }
private String buildSymbolName(String hash, Address addr) { private String buildSymbolName(String hash, Address addr) {
@ -174,7 +177,7 @@ public class DataTypeSymbol {
return res; return res;
} }
public static String generateHash(DataType dt) { public static int generateHash(DataType dt) {
String material; String material;
if (dt instanceof FunctionSignature) if (dt instanceof FunctionSignature)
material = ((FunctionSignature) dt).getPrototypeString(true); material = ((FunctionSignature) dt).getPrototypeString(true);
@ -191,7 +194,7 @@ public class DataTypeSymbol {
hash = SimpleCRC32.hashOneByte(hash, material.charAt(i)); hash = SimpleCRC32.hashOneByte(hash, material.charAt(i));
} }
} }
return Integer.toHexString(hash); return hash;
} }
public static String extractHash(String symname) { public static String extractHash(String symname) {