GP-6136 fix ByteViewer exception when clicking on partial line

ByteViewer formats that use several bytes (eg. hex long, hex long long)
cause a class cast exception when a row with partial data is displayed.
This commit is contained in:
dev747368
2025-11-18 22:47:02 +00:00
parent 4c7ea237c3
commit a55990bd3a

View File

@@ -566,18 +566,13 @@ public class ByteViewerComponent extends FieldPanel implements FieldMouseListene
return characterOffset;
}
int column = fieldLoc.getCol() + characterOffset;
int fieldNum = fieldLoc.getFieldNum();
int fieldRow = fieldLoc.getRow();
ByteField field = (ByteField) layout.getField(fieldNum);
if (field != null) {
// not sure this can be null
int numCols = field.getNumCols(fieldRow);
if (column >= numCols) {
column = numCols - 1;
}
if (!(layout.getField(fieldNum) instanceof ByteField field)) {
return characterOffset;
}
int column = Math.clamp(fieldLoc.getCol() + characterOffset, 0,
field.getNumCols(fieldLoc.getRow()) - 1);
return column;
}