diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clipboard/CodeBrowserClipboardProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clipboard/CodeBrowserClipboardProvider.java index 36205f109a..cdc2085986 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clipboard/CodeBrowserClipboardProvider.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clipboard/CodeBrowserClipboardProvider.java @@ -760,8 +760,10 @@ public class CodeBrowserClipboardProvider extends ByteCopier CommentFieldLocation commentFieldLocation = (CommentFieldLocation) currentLocation; Address address = commentFieldLocation.getAddress(); CommentType commentType = commentFieldLocation.getCommentType(); - SetCommentCmd cmd = new SetCommentCmd(address, commentType, string); - return tool.execute(cmd, currentProgram); + if (commentType != null) { + SetCommentCmd cmd = new SetCommentCmd(address, commentType, string); + return tool.execute(cmd, currentProgram); + } } return false; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/comments/CommentsPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/comments/CommentsPlugin.java index 5f13f80390..f30b2ccbfa 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/comments/CommentsPlugin.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/comments/CommentsPlugin.java @@ -255,6 +255,9 @@ public class CommentsPlugin extends Plugin implements OptionsChangeListener { CommentFieldLocation cfLoc = (CommentFieldLocation) loc; CommentType type = cfLoc.getCommentType(); + if (type == null) { + return; + } switch (type) { case PRE: action.getPopupMenuData() diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/CommentTypeUtils.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/CommentTypeUtils.java index 4bfd08484c..d70270a775 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/CommentTypeUtils.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/CommentTypeUtils.java @@ -26,13 +26,17 @@ public class CommentTypeUtils { * @param cu * @param loc * @param defaultCommentType - * @return comment type + * @return comment type or defaultCommentType if location does not correspond + * to a comment */ public static CommentType getCommentType(CodeUnit cu, ProgramLocation loc, CommentType defaultCommentType) { if (loc instanceof CommentFieldLocation) { CommentFieldLocation cfLoc = (CommentFieldLocation) loc; - return cfLoc.getCommentType(); + CommentType type = cfLoc.getCommentType(); + if (type != null) { + return type; + } } else if (loc instanceof PlateFieldLocation) { return CommentType.PLATE;