Skip to content

Commit 4f73af4

Browse files
committed
Correct divide-by-zero test issue
1 parent c081a87 commit 4f73af4

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/AbstractConvertAction.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ public AbstractConvertAction(EquatePlugin plugin, String actionName, boolean isS
4242
this.isSigned = isSigned;
4343
setPopupMenuData(new MenuData(new String[] { "Convert", "" }, "Convert"));
4444
setEnabled(true);
45-
JMenuItem item = new JMenuItem();
46-
Font font = item.getFont();
47-
metrics = plugin.getTool().getActiveWindow().getFontMetrics(font);
48-
4945
}
5046

5147
@Override
@@ -132,14 +128,28 @@ protected final boolean isSignedChoice() {
132128
return isSigned;
133129
}
134130

131+
private int stringWidth(String s) {
132+
if (metrics == null) {
133+
JMenuItem item = new JMenuItem();
134+
Font font = item.getFont();
135+
metrics = plugin.getTool().getActiveWindow().getFontMetrics(font);
136+
}
137+
int w = metrics.stringWidth(s);
138+
if (w == 0) {
139+
// use default computation if metrics report 0
140+
return 10 * s.length();
141+
}
142+
return w;
143+
}
144+
135145
String getStandardLengthString(String baseString) {
136-
int baseWidth = metrics.stringWidth(baseString);
137-
int spaceWidth = metrics.stringWidth(" ");
146+
int baseWidth = stringWidth(baseString);
147+
int spaceWidth = stringWidth(" ");
138148
int paddingSize = (140 - baseWidth) / spaceWidth;
139149
if (paddingSize <= 0) {
140150
return baseString;
141151
}
142-
StringBuffer buf = new StringBuffer(baseString);
152+
StringBuilder buf = new StringBuilder(baseString);
143153
for (int i = 0; i < paddingSize; i++) {
144154
buf.append(" ");
145155
}

0 commit comments

Comments
 (0)