From 3e38574f8bd131bfc6824836473b3cc810e1e738 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Fri, 27 Nov 2020 23:06:52 +0100 Subject: [PATCH] Fixed NPE in ExpressionHandler --- .../aisec/cpg/frontends/cpp/ExpressionHandler.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/fraunhofer/aisec/cpg/frontends/cpp/ExpressionHandler.java b/src/main/java/de/fraunhofer/aisec/cpg/frontends/cpp/ExpressionHandler.java index 67579314bc..d7aded17a4 100644 --- a/src/main/java/de/fraunhofer/aisec/cpg/frontends/cpp/ExpressionHandler.java +++ b/src/main/java/de/fraunhofer/aisec/cpg/frontends/cpp/ExpressionHandler.java @@ -292,12 +292,15 @@ private Expression handleSimpleTypeConstructorExpression( private Expression handleFieldReference(CPPASTFieldReference ctx) { Expression base = this.handle(ctx.getFieldOwner()); // Replace Literal this with a reference pointing to this - if (base instanceof Literal && ((Literal) base).getValue().equals("this")) { + if (base instanceof Literal && ((Literal) base).getValue().equals("this")) { PhysicalLocation location = base.getLocation(); + + var record = lang.getScopeManager().getCurrentRecord(); + base = NodeBuilder.newDeclaredReferenceExpression( "this", - lang.getScopeManager().getCurrentRecord().getThis().getType(), + record != null ? record.getThis().getType() : UnknownType.getUnknownType(), base.getCode()); base.setLocation(location); }