fix: clear sufficient space when changing data types

When applying a larger struct to an address, clear enough space
for the new data type rather than just the old data's length.
This prevents 'Conflicting data exists' errors when the new
type is larger than the existing data.

Fixes issue where ConfigParametersStruct couldn't be applied
due to conflicting smaller data items in the address range.
This commit is contained in:
Teal Bauer 2025-11-14 13:20:49 +01:00
parent f32dc5504c
commit 60124d2315

View File

@ -532,11 +532,16 @@ package eu.starsong.ghidra.endpoints;
if (dataType == null) {
throw new Exception("Could not find or parse data type: " + dataTypeStr);
}
// Clear existing data
int length = data.getLength();
listing.clearCodeUnits(addr, addr.add(length - 1), false);
// Clear existing data - need to clear enough space for the new data type
// Use the LARGER of the old data length or new data type length
int oldLength = data.getLength();
int newLength = dataType.getLength();
int lengthToClear = Math.max(oldLength, newLength > 0 ? newLength : oldLength);
// Clear the required space
listing.clearCodeUnits(addr, addr.add(lengthToClear - 1), false);
// Create new data
Data newData = listing.createData(addr, dataType);
if (newData == null) {