Ghidra is a software reverse engineering (SRE) framework
GP-4891 - Fixed an exception in the Stack editor when editing and using the down arrow
dragonmacher28ea0c99f023
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.javaindex 98896f03a4..19eb46de69 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java@@ -486,8 +486,8 @@ public abstract class CompositeEditorPanel extends JPanelif (index >= 0) {row = index;table.setRowSelectionInterval(row, row);- if (model.isCellEditable(index, modelColumn)) {- return beginEditField(model.getRow(), model.getColumn());+ if (model.isCellEditable(row, modelColumn)) {+ return beginEditField(row, modelColumn);}}return false;@@ -500,6 +500,7 @@ public abstract class CompositeEditorPanel extends JPanelprotected boolean editBelowField() {int row = model.getRow();int modelColumn = model.getColumn();+// Get the current row (index) and column (fieldNum).int index = row;index++;@@ -508,8 +509,8 @@ public abstract class CompositeEditorPanel extends JPanelif (index < numComps) {row = index;table.setRowSelectionInterval(row, row);- if (model.isCellEditable(index, modelColumn)) {- return beginEditField(model.getRow(), model.getColumn());+ if (model.isCellEditable(row, modelColumn)) {+ return beginEditField(row, modelColumn);}}return false;@@ -602,7 +603,7 @@ public abstract class CompositeEditorPanel extends JPanelmodel.setColumn(modelIndex);}else {- model.setColumn(-1);+ model.setColumn(e.getFirstIndex());}});diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/stackeditor/StackEditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/stackeditor/StackEditorModel.javaindex 183d162308..71607a065e 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/stackeditor/StackEditorModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/stackeditor/StackEditorModel.java@@ -406,22 +406,16 @@ public class StackEditorModel extends CompositeEditorModel {if (columnIndex == LENGTH) {return false;}- if ((rowIndex < 0) || (rowIndex >= getRowCount())) {+ if (rowIndex < 0 || rowIndex >= getRowCount()) {+ return false;+ }+ if (columnIndex < 0 || columnIndex >= getColumnCount()) {return false;}DataTypeComponent dtc = stackDt.getComponent(rowIndex);if (dtc == null) {return false;}-// if (columnIndex != NAME) {-// int offset = dtc.getOffset();-// if (!hasCustomParameterStorage && originalStack.isParameterOffset(offset)) {-// return false;-// }-// }-// if (dtc.getDataType() instanceof StackPieceDataType) {-// return false;-// }boolean notDefined = (stackDt.getDefinedComponentAtOrdinal(rowIndex) == null);return !(notDefined && (columnIndex == OFFSET));}diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.javaindex 448f89aca1..4296fa4dcd 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -474,6 +474,16 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegrationwaitForSwing();}+ protected void downArrow() {+ triggerActionKey(getTable(), 0, KeyEvent.VK_DOWN);+ waitForSwing();+ }++ protected void downArrow(JComponent component) {+ triggerActionKey(component, 0, KeyEvent.VK_DOWN);+ waitForSwing();+ }+protected void endKey() {triggerActionKey(getKeyEventDestination(), 0, KeyEvent.VK_END);waitForSwing();diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/StackEditorProvider1Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/StackEditorProvider1Test.javaindex 76afce5a1c..f743505a68 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/StackEditorProvider1Test.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/stackeditor/StackEditorProvider1Test.java@@ -139,6 +139,29 @@ public class StackEditorProvider1Test extends AbstractStackEditorProviderTest {assertStackEditorHidden(function);}+ @Test+ public void testEditUsingArrowKeys() throws Exception {++ init(SIMPLE_STACK);++ int row = 1;+ int column = model.getNameColumn();+ clickTableCell(getTable(), row, column, 1);+ assertColumn(column);+ performAction(editFieldAction, provider, true);++ // change name+ JTextField tf = getCellEditorTextField();+ setText(tf, tf.getText() + "change");++ downArrow(tf);+ assertRow(row + 1);+ assertColumn(column);++ assertIsEditingField(row + 1, column);+ escape();+ }+@Testpublic void testDeleteAssociatedFunction() throws Exception {Window dialog;