Skip to content

Commit

Permalink
[Clang] Fix null pointer dereference in VisitUsingEnumDecl (llvm#97910)
Browse files Browse the repository at this point in the history
This patch addresses static analyzer concern where TSI could be
dereferenced after being assigned a null value from SubstType in
clang::TemplateDeclInstantiator::VisitUsingEnumDecl(clang::UsingEnumDecl
*).

The fix now checks null value of TSI after the call to SubstType and
return nullptr to prevent potential null pointer dereferences when
calling UsingEnumDecl::Create() and ensures safe execution.
  • Loading branch information
smanna12 authored Jul 10, 2024
1 parent 4753f8e commit 0162df0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3420,6 +3420,10 @@ Decl *TemplateDeclInstantiator::VisitUsingEnumDecl(UsingEnumDecl *D) {

TypeSourceInfo *TSI = SemaRef.SubstType(D->getEnumType(), TemplateArgs,
D->getLocation(), D->getDeclName());

if (!TSI)
return nullptr;

UsingEnumDecl *NewUD =
UsingEnumDecl::Create(SemaRef.Context, Owner, D->getUsingLoc(),
D->getEnumLoc(), D->getLocation(), TSI);
Expand Down

0 comments on commit 0162df0

Please sign in to comment.