1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

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
This commit is contained in:
Jonah Graham 2023-01-18 20:35:31 -05:00
parent b7fac2cfaf
commit db84fe490d

View file

@ -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;
}
}
}
}