Skip to content

Commit f7fec8c

Browse files
authored
[Clang] Prevent null pointer dereference in template deduction guide creation (#97097)
This patch addresses static analyzer concerns where `TSI` could be dereferenced after being assigned a null value from `SubstType` in `ConvertConstructorToDeductionGuideTransform()`. The fixes now check null value of `TSI` after the call to `SubstType` and return `nullptr` to prevent potential null pointer dereferences when calling getTypeLoc() or getType() and ensure safe execution.
1 parent 1791b11 commit f7fec8c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,6 +2513,9 @@ struct ConvertConstructorToDeductionGuideTransform {
25132513
TSI = SemaRef.SubstType(TSI, OuterInstantiationArgs, Loc,
25142514
DeductionGuideName);
25152515

2516+
if (!TSI)
2517+
return nullptr;
2518+
25162519
FunctionProtoTypeLoc FPTL =
25172520
TSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
25182521

@@ -2523,6 +2526,9 @@ struct ConvertConstructorToDeductionGuideTransform {
25232526
if (NestedPattern)
25242527
TSI = SemaRef.SubstType(TSI, OuterInstantiationArgs, Loc,
25252528
DeclarationName());
2529+
if (!TSI)
2530+
return nullptr;
2531+
25262532
ParmVarDecl *NewParam =
25272533
ParmVarDecl::Create(SemaRef.Context, DC, Loc, Loc, nullptr,
25282534
TSI->getType(), TSI, SC_None, nullptr);

0 commit comments

Comments
 (0)