From 60124d2315322eaeefc2ae741ae823fa89f2b69d Mon Sep 17 00:00:00 2001 From: Teal Bauer Date: Fri, 14 Nov 2025 13:20:49 +0100 Subject: [PATCH] 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. --- .../starsong/ghidra/endpoints/DataEndpoints.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/starsong/ghidra/endpoints/DataEndpoints.java b/src/main/java/eu/starsong/ghidra/endpoints/DataEndpoints.java index 7995398..d09caa3 100644 --- a/src/main/java/eu/starsong/ghidra/endpoints/DataEndpoints.java +++ b/src/main/java/eu/starsong/ghidra/endpoints/DataEndpoints.java @@ -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) {