GP-4756 corrected StructureDB length update issue

This commit is contained in:
ghidra1 2024-07-08 15:23:52 -04:00
parent aa29ddea12
commit f77b7b60f8

View file

@ -215,7 +215,7 @@ class StructureDB extends CompositeDB implements StructureInternal {
++numComponents; ++numComponents;
structLength += structureGrowth; structLength += structureGrowth;
if (validatePackAndNotify) { if (validatePackAndNotify) { // else caller responsible for record updates
if (isPackingEnabled()) { if (isPackingEnabled()) {
repack(false, false); // may not recognize length change repack(false, false); // may not recognize length change
} }
@ -1684,6 +1684,9 @@ class StructureDB extends CompositeDB implements StructureInternal {
private void doReplaceWithNonPacked(Structure struct, DataType[] resolvedDts) private void doReplaceWithNonPacked(Structure struct, DataType[] resolvedDts)
throws IOException { throws IOException {
// caller responsible for record updates
// assumes components is clear and that alignment characteristics have been set. // assumes components is clear and that alignment characteristics have been set.
if (struct.isNotYetDefined()) { if (struct.isNotYetDefined()) {
return; return;
@ -1728,7 +1731,7 @@ class StructureDB extends CompositeDB implements StructureInternal {
private void doCopy(Structure struct, DataTypeComponent[] definedComponents, private void doCopy(Structure struct, DataTypeComponent[] definedComponents,
DataType[] resolvedDts) throws IOException { DataType[] resolvedDts) throws IOException {
// simple replication of struct // simple replication of struct - caller must perform record updates
structLength = struct.isZeroLength() ? 0 : struct.getLength(); structLength = struct.isZeroLength() ? 0 : struct.getLength();
numComponents = struct.getNumComponents(); numComponents = struct.getNumComponents();
structAlignment = struct.getAlignment(); structAlignment = struct.getAlignment();
@ -2469,18 +2472,21 @@ class StructureDB extends CompositeDB implements StructureInternal {
private boolean updateComposite(int currentNumComponents, int currentLength, private boolean updateComposite(int currentNumComponents, int currentLength,
int currentAlignment, boolean setLastChangeTime) { int currentAlignment, boolean setLastChangeTime) {
boolean compositeChanged = false; boolean compositeChanged = false;
if (currentNumComponents >= 0 && numComponents != currentNumComponents) { if (currentNumComponents >= 0 && currentNumComponents != record
.getIntValue(CompositeDBAdapter.COMPOSITE_NUM_COMPONENTS_COL)) {
numComponents = currentNumComponents; numComponents = currentNumComponents;
record.setIntValue(CompositeDBAdapter.COMPOSITE_NUM_COMPONENTS_COL, numComponents); record.setIntValue(CompositeDBAdapter.COMPOSITE_NUM_COMPONENTS_COL, numComponents);
setLastChangeTime = true; setLastChangeTime = true;
compositeChanged = true; compositeChanged = true;
} }
if (currentLength >= 0 && structLength != currentLength) { if (currentLength >= 0 &&
currentLength != record.getIntValue(CompositeDBAdapter.COMPOSITE_LENGTH_COL)) {
structLength = currentLength; structLength = currentLength;
record.setIntValue(CompositeDBAdapter.COMPOSITE_LENGTH_COL, structLength); record.setIntValue(CompositeDBAdapter.COMPOSITE_LENGTH_COL, structLength);
compositeChanged = true; compositeChanged = true;
} }
if (currentAlignment >= 0 && structAlignment != currentAlignment) { if (currentAlignment >= 0 &&
currentAlignment != record.getIntValue(CompositeDBAdapter.COMPOSITE_ALIGNMENT_COL)) {
structAlignment = currentAlignment; structAlignment = currentAlignment;
record.setIntValue(CompositeDBAdapter.COMPOSITE_ALIGNMENT_COL, structAlignment); record.setIntValue(CompositeDBAdapter.COMPOSITE_ALIGNMENT_COL, structAlignment);
compositeChanged = true; compositeChanged = true;