Skip to content

Commit

Permalink
Updated getTableRowIndex to be more safe
Browse files Browse the repository at this point in the history
Modified getTableRowIndex to add a sufficient number of rows
in case the resulting index lies outside of current visible
address space.
  • Loading branch information
gzachos committed Aug 5, 2019
1 parent c3c0c89 commit bf9568f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions mars/tools/StackVisualizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ else if (row > spDataRowIndex) {
color = LIGHT_GRAY;
}
c.setBackground(new Color(color));

// TODO: refactor
if (dataPerByte.isSelected()) {
if (column >= FIRST_BYTE_COLUMN && column <= LAST_BYTE_COLUMN)
Expand Down Expand Up @@ -227,7 +227,7 @@ public void actionPerformed(ActionEvent e) {
panel.add(hexValuesCheckBox, c);
return panel;
}

private void transformTableModel(String columnNames[]) {
int rowCount = tableModel.getRowCount();
Object storedRegColumnData[] = new Object[rowCount];
Expand All @@ -236,7 +236,7 @@ private void transformTableModel(String columnNames[]) {
storedRegColumnData[i] = tableModel.getValueAt(i, storedRegisterColumn);
frameNameColumnData[i] = tableModel.getValueAt(i, frameNameColumn);
}

tableModel.setColumnCount(0); // clearing columns of table
for (String s : columnNames) {
tableModel.addColumn(s); // setting new columns
Expand Down Expand Up @@ -519,7 +519,7 @@ private void processStackMemoryUpdate(MemoryAccessNotice notice) {
} else {
regName = "";
}

if (frameNameToBeCreated != null) {
frameName = frameNameToBeCreated;
frameNameToBeCreated = null;
Expand Down Expand Up @@ -550,7 +550,15 @@ private int getTableRowIndex(int memAddress) {
System.err.println("getTableRowIndex() only works for stack segment addresses");
return -1;
}
return (maxSpValueWordAligned - alignToCurrentWordBoundary(memAddress)) / WORD_LENGTH_BYTES;
int rowIndex = (maxSpValueWordAligned - alignToCurrentWordBoundary(memAddress)) / WORD_LENGTH_BYTES;
if (rowIndex > tableModel.getRowCount()) {
// TODO: export a function for adding more table rows
for (int i = 0; i < rowIndex - tableModel.getRowCount() + 10; i++)
tableModel.addRow(new Object[numberOfColumns]);
getStackData();
table.repaint();
}
return rowIndex;
}

private int getTableColumnIndex(int memAddress) {
Expand Down

0 comments on commit bf9568f

Please sign in to comment.