From a2725fd03febf32051811af2fa50fd0de3b61dde Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 6 May 2021 16:08:15 -0700 Subject: Fix for uninitialized field (#1838) The `OverloadedExpr` type didn't provide a default value for its field: Name* name; This led to a null-pointer crash in the logic that deals with synthesizing interface requirements because it creates an `OverloadedExpr` but doesn't initialize the field. This change makes two fixes: 1. The logic in the synthesis path actually initializes `name` so that it can feed into any downstream error messages 2. The `OverloadedExpr` declaration now includes an initial value for `name` so that it will at least be null instead of garbage if we slip up again --- source/slang/slang-ast-expr.h | 2 +- source/slang/slang-check-decl.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/source/slang/slang-ast-expr.h b/source/slang/slang-ast-expr.h index a5024460b..d79982b5d 100644 --- a/source/slang/slang-ast-expr.h +++ b/source/slang/slang-ast-expr.h @@ -35,7 +35,7 @@ class OverloadedExpr : public Expr SLANG_AST_CLASS(OverloadedExpr) // The name that was looked up and found to be overloaded - Name* name; + Name* name = nullptr; // Optional: the base expression is this overloaded result // arose from a member-reference expression. diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 726781fb0..0f6075903 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -2062,6 +2062,7 @@ namespace Slang // expression. // auto synBase = m_astBuilder->create(); + synBase->name = requiredMemberDeclRef.getDecl()->getName(); synBase->lookupResult2 = lookupResult; // If `synThis` is non-null, then we will use it as the base of -- cgit v1.2.3