GP-3020 - Updated the Fill in Structure action to take into account the

structure size
This commit is contained in:
dragonmacher
2023-01-17 14:24:04 -05:00
parent 991f84686c
commit fc6fb6e4ae

View File

@@ -559,12 +559,16 @@ public class FillOutStructureCmd extends BackgroundCommand {
return currentProgram.getDataTypeManager().getUniqueName(new CategoryPath(category), base);
}
private boolean sanityCheck(long offset) {
private boolean sanityCheck(long offset, long existingSize) {
if (offset < 0) {
return false; // offsets shouldn't be negative
}
if (offset < existingSize) {
return true; // we have room in the structure
}
if (offset > 0x1000) {
return false; // Arbitrary size cut-off to prevent creating huge structures
return false; // bigger than existing size; arbitrary cut-off to prevent huge structures
}
return true;
}
@@ -648,7 +652,7 @@ public class FillOutStructureCmd extends BackgroundCommand {
long value = getSigned(inputs[1]);
newOff = currentRef.offset +
((pcodeOp.getOpcode() == PcodeOp.INT_ADD) ? value : (-value));
if (sanityCheck(newOff)) { // should this offset create a location in the structure?
if (sanityCheck(newOff, componentMap.getSize())) { // should this offset create a location in the structure?
putOnList(output, newOff, todoList, doneList);
// Don't do componentMap.addDataType() as data-type info here is likely uninformed
componentMap.setMinimumSize(newOff);
@@ -659,7 +663,7 @@ public class FillOutStructureCmd extends BackgroundCommand {
break;
}
newOff = currentRef.offset + getSigned(inputs[1]) * inputs[2].getOffset();
if (sanityCheck(newOff)) { // should this offset create a location in the structure?
if (sanityCheck(newOff, componentMap.getSize())) { // should this offset create a location in the structure?
putOnList(output, newOff, todoList, doneList);
// Don't do componentMap.addReference() as data-type info here is likely uninformed
componentMap.setMinimumSize(newOff);
@@ -670,7 +674,7 @@ public class FillOutStructureCmd extends BackgroundCommand {
break;
}
long subOff = currentRef.offset + getSigned(inputs[1]);
if (sanityCheck(subOff)) { // should this offset create a location in the structure?
if (sanityCheck(subOff, componentMap.getSize())) { // should this offset create a location in the structure?
putOnList(output, subOff, todoList, doneList);
// Don't do componentMap.addReference() as data-type info here is likely uninformed
componentMap.setMinimumSize(subOff);