mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
Merge remote-tracking branch 'origin/GP-2228-dragonmacher-structured-editor-error-message'
This commit is contained in:
commit
d069fbad2b
1 changed files with 20 additions and 14 deletions
|
@ -568,10 +568,11 @@ public abstract class CompEditorModel extends CompositeEditorModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataTypeComponent add(DataType dataType) throws UsrException {
|
public DataTypeComponent add(DataType dataType) throws UsrException {
|
||||||
if (isContiguousSelection()) {
|
if (!isContiguousSelection()) {
|
||||||
return add(getMinIndexSelected(), dataType);
|
setStatus("Replace data type only works on a contiguous selection", true);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
return add(getMinIndexSelected(), dataType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -822,7 +823,8 @@ public abstract class CompEditorModel extends CompositeEditorModel {
|
||||||
* @param length component length
|
* @param length component length
|
||||||
* @throws InvalidDataTypeException if check fails
|
* @throws InvalidDataTypeException if check fails
|
||||||
*/
|
*/
|
||||||
private void checkForReplace(int rowIndex, DataType datatype, int length) throws InvalidDataTypeException {
|
private void checkForReplace(int rowIndex, DataType datatype, int length)
|
||||||
|
throws InvalidDataTypeException {
|
||||||
DataTypeComponent dtc = getComponent(rowIndex);
|
DataTypeComponent dtc = getComponent(rowIndex);
|
||||||
if (dtc == null) {
|
if (dtc == null) {
|
||||||
throw new InvalidDataTypeException("Invalid component selection");
|
throw new InvalidDataTypeException("Invalid component selection");
|
||||||
|
@ -851,14 +853,17 @@ public abstract class CompEditorModel extends CompositeEditorModel {
|
||||||
int undefinedSpaceAvail = getNumUndefinedBytesAfter(dtc);
|
int undefinedSpaceAvail = getNumUndefinedBytesAfter(dtc);
|
||||||
if (sizeDiff > undefinedSpaceAvail) {
|
if (sizeDiff > undefinedSpaceAvail) {
|
||||||
int spaceNeeded = sizeDiff - undefinedSpaceAvail;
|
int spaceNeeded = sizeDiff - undefinedSpaceAvail;
|
||||||
String msg = newCompSize + " byte replacement at 0x" + Integer.toHexString(dtc.getOffset());
|
String msg =
|
||||||
|
newCompSize + " byte replacement at 0x" + Integer.toHexString(dtc.getOffset());
|
||||||
if (struct.getDefinedComponentAtOrAfterOffset(dtc.getOffset() + 1) == null) {
|
if (struct.getDefinedComponentAtOrAfterOffset(dtc.getOffset() + 1) == null) {
|
||||||
// suggest growing structure
|
// suggest growing structure
|
||||||
int suggestedSize = getLength() + spaceNeeded;
|
int suggestedSize = getLength() + spaceNeeded;
|
||||||
throw new InvalidDataTypeException(msg + " requires structure length of " + suggestedSize + "-bytes.");
|
throw new InvalidDataTypeException(
|
||||||
|
msg + " requires structure length of " + suggestedSize + "-bytes.");
|
||||||
}
|
}
|
||||||
// suggest insert bytes (NOTE: in the future a conflict removal/grow could be offered)
|
// suggest insert bytes (NOTE: in the future a conflict removal/grow could be offered)
|
||||||
throw new InvalidDataTypeException(msg + " requires " + spaceNeeded + " additional undefined bytes.");
|
throw new InvalidDataTypeException(
|
||||||
|
msg + " requires " + spaceNeeded + " additional undefined bytes.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -886,9 +891,10 @@ public abstract class CompEditorModel extends CompositeEditorModel {
|
||||||
if (nextCompOffset >= length) {
|
if (nextCompOffset >= length) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DataTypeComponent nextDefinedDtc = struct.getDefinedComponentAtOrAfterOffset(nextCompOffset);
|
DataTypeComponent nextDefinedDtc =
|
||||||
|
struct.getDefinedComponentAtOrAfterOffset(nextCompOffset);
|
||||||
int nextDefinedOffset = (nextDefinedDtc == null) ? length : nextDefinedDtc.getOffset();
|
int nextDefinedOffset = (nextDefinedDtc == null) ? length : nextDefinedDtc.getOffset();
|
||||||
return Math.max(0, nextDefinedOffset - nextCompOffset); // prevent negative return value
|
return Math.max(0, nextDefinedOffset - nextCompOffset); // prevent negative return value
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue