mirror of
https://github.com/NationalSecurityAgency/ghidra
synced 2024-10-13 13:43:00 +00:00
Fix NPE in selectFieldNumber in ForceUnionAction.java
If the allFields ArrayList contains element null, findStringIndex() will throw a NPE. Use allFields.indexOf() will not have this issue.
This commit is contained in:
parent
357ff97cb3
commit
bee69b2f38
|
@ -189,21 +189,6 @@ public class ForceUnionAction extends AbstractDecompilerAction {
|
|||
return resArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the index of a given string, within an array of strings
|
||||
* @param list is the array of strings
|
||||
* @param value is the given string to find
|
||||
* @return the index of the given string within the array, or -1 if it isn't present
|
||||
*/
|
||||
private static int findStringIndex(ArrayList<String> list, String value) {
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
if (list.get(i).equals(value)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Let the user choose the particular field to force on the selected Varnode. The names
|
||||
* of the fields in the associated union are presented, possibly along with the special
|
||||
|
@ -224,7 +209,7 @@ public class ForceUnionAction extends AbstractDecompilerAction {
|
|||
OkDialog.show("No Field Choices", "Only one field fits the selected variable");
|
||||
return false;
|
||||
}
|
||||
int currentChoice = findStringIndex(allFields, defaultFieldName);
|
||||
int currentChoice = allFields.indexOf(defaultFieldName);
|
||||
if (currentChoice < 0) {
|
||||
defaultFieldName = null;
|
||||
}
|
||||
|
@ -234,7 +219,7 @@ public class ForceUnionAction extends AbstractDecompilerAction {
|
|||
if (userChoice == null) {
|
||||
return false; // User cancelled when making the choice
|
||||
}
|
||||
fieldNumber = findStringIndex(allFields, userChoice);
|
||||
fieldNumber = allFields.indexOf(userChoice);
|
||||
if (fieldNumber < 0 || fieldNumber == currentChoice) {
|
||||
return false; // User chose original value or something not in list, treat as cancel
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue