mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +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:
parent
b7fac2cfaf
commit
db84fe490d
1 changed files with 9 additions and 4 deletions
|
@ -296,6 +296,9 @@ public abstract class AbstractDebugTextHover implements ICEditorTextHover, IText
|
||||||
|
|
||||||
private void computeMacroArgumentExtent(IASTName name, Position pos) {
|
private void computeMacroArgumentExtent(IASTName name, Position pos) {
|
||||||
IASTImageLocation imageLoc = name.getImageLocation();
|
IASTImageLocation imageLoc = name.getImageLocation();
|
||||||
|
if (imageLoc == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int startOffset = imageLoc.getNodeOffset();
|
int startOffset = imageLoc.getNodeOffset();
|
||||||
int endOffset = startOffset + imageLoc.getNodeLength();
|
int endOffset = startOffset + imageLoc.getNodeLength();
|
||||||
// do some black magic to consider field reference expressions
|
// do some black magic to consider field reference expressions
|
||||||
|
@ -314,10 +317,12 @@ public abstract class AbstractDebugTextHover implements ICEditorTextHover, IText
|
||||||
if (ownerExpr instanceof IASTIdExpression) {
|
if (ownerExpr instanceof IASTIdExpression) {
|
||||||
IASTName ownerName = ((IASTIdExpression) ownerExpr).getName();
|
IASTName ownerName = ((IASTIdExpression) ownerExpr).getName();
|
||||||
IASTImageLocation ownerImageLoc = ownerName.getImageLocation();
|
IASTImageLocation ownerImageLoc = ownerName.getImageLocation();
|
||||||
final int nameOffset = ownerImageLoc.getNodeOffset();
|
if (ownerImageLoc != null) {
|
||||||
// offset should be inside macro expansion
|
final int nameOffset = ownerImageLoc.getNodeOffset();
|
||||||
if (nameOffset < startOffset && nameOffset > macroOffset) {
|
// offset should be inside macro expansion
|
||||||
startOffset = nameOffset;
|
if (nameOffset < startOffset && nameOffset > macroOffset) {
|
||||||
|
startOffset = nameOffset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue