From db84fe490dbedcd070630b1586ad15ccdb4c8328 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Wed, 18 Jan 2023 20:35:31 -0500 Subject: [PATCH] Handle case where AST name has no location In cases where an IASTName has no image location we were getting NPEs in this code. See javadoc for getImageLocation for cases when image location can be null. See #251's description for a full case of when this can happen. All other calls to IASTName.getImageLocation in CDT were also checked and this was the only place in the code where the return value was not checked for null. Fixes #251 --- .../debug/ui/editors/AbstractDebugTextHover.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/editors/AbstractDebugTextHover.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/editors/AbstractDebugTextHover.java index 042e3568eec..bcf2e526168 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/editors/AbstractDebugTextHover.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/editors/AbstractDebugTextHover.java @@ -296,6 +296,9 @@ public abstract class AbstractDebugTextHover implements ICEditorTextHover, IText private void computeMacroArgumentExtent(IASTName name, Position pos) { IASTImageLocation imageLoc = name.getImageLocation(); + if (imageLoc == null) { + return; + } int startOffset = imageLoc.getNodeOffset(); int endOffset = startOffset + imageLoc.getNodeLength(); // do some black magic to consider field reference expressions @@ -314,10 +317,12 @@ public abstract class AbstractDebugTextHover implements ICEditorTextHover, IText if (ownerExpr instanceof IASTIdExpression) { IASTName ownerName = ((IASTIdExpression) ownerExpr).getName(); IASTImageLocation ownerImageLoc = ownerName.getImageLocation(); - final int nameOffset = ownerImageLoc.getNodeOffset(); - // offset should be inside macro expansion - if (nameOffset < startOffset && nameOffset > macroOffset) { - startOffset = nameOffset; + if (ownerImageLoc != null) { + final int nameOffset = ownerImageLoc.getNodeOffset(); + // offset should be inside macro expansion + if (nameOffset < startOffset && nameOffset > macroOffset) { + startOffset = nameOffset; + } } } }