mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
Correct divide-by-zero test issue
This commit is contained in:
parent
af5e11e034
commit
fce7cd0a9a
1 changed files with 17 additions and 7 deletions
|
@ -42,10 +42,6 @@ public abstract class AbstractConvertAction extends ListingContextAction {
|
|||
this.isSigned = isSigned;
|
||||
setPopupMenuData(new MenuData(new String[] { "Convert", "" }, "Convert"));
|
||||
setEnabled(true);
|
||||
JMenuItem item = new JMenuItem();
|
||||
Font font = item.getFont();
|
||||
metrics = plugin.getTool().getActiveWindow().getFontMetrics(font);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -132,14 +128,28 @@ public abstract class AbstractConvertAction extends ListingContextAction {
|
|||
return isSigned;
|
||||
}
|
||||
|
||||
private int stringWidth(String s) {
|
||||
if (metrics == null) {
|
||||
JMenuItem item = new JMenuItem();
|
||||
Font font = item.getFont();
|
||||
metrics = plugin.getTool().getActiveWindow().getFontMetrics(font);
|
||||
}
|
||||
int w = metrics.stringWidth(s);
|
||||
if (w == 0) {
|
||||
// use default computation if metrics report 0
|
||||
return 10 * s.length();
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
String getStandardLengthString(String baseString) {
|
||||
int baseWidth = metrics.stringWidth(baseString);
|
||||
int spaceWidth = metrics.stringWidth(" ");
|
||||
int baseWidth = stringWidth(baseString);
|
||||
int spaceWidth = stringWidth(" ");
|
||||
int paddingSize = (140 - baseWidth) / spaceWidth;
|
||||
if (paddingSize <= 0) {
|
||||
return baseString;
|
||||
}
|
||||
StringBuffer buf = new StringBuffer(baseString);
|
||||
StringBuilder buf = new StringBuilder(baseString);
|
||||
for (int i = 0; i < paddingSize; i++) {
|
||||
buf.append(" ");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue