Skip to content

Commit

Permalink
[NFC][CLANG] Fix nullptr dereference issue in DeduceTemplateArguments…
Browse files Browse the repository at this point in the history
…ByTypeMatch()

DeduceTemplateArgumentsByTypeMatch() returns null value which is dereferenced without checking since getAsIncompleteArrayType() returns nullptr and we are dereferencing null pointer value for S.Context->getAsIncompleteArrayType(P) when calling getElementType().

This patch adds an assert.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D151529
  • Loading branch information
smanna12 committed May 31, 2023
1 parent 62307f6 commit cf236a0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions clang/lib/Sema/SemaTemplateDeduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1703,10 +1703,12 @@ static Sema::TemplateDeductionResult DeduceTemplateArgumentsByTypeMatch(
if (!IAA)
return Sema::TDK_NonDeducedMismatch;

const auto *IAP = S.Context.getAsIncompleteArrayType(P);
assert(IAP && "Template parameter not of incomplete array type");

return DeduceTemplateArgumentsByTypeMatch(
S, TemplateParams,
S.Context.getAsIncompleteArrayType(P)->getElementType(),
IAA->getElementType(), Info, Deduced, TDF & TDF_IgnoreQualifiers);
S, TemplateParams, IAP->getElementType(), IAA->getElementType(), Info,
Deduced, TDF & TDF_IgnoreQualifiers);
}

// T [integer-constant]
Expand Down

0 comments on commit cf236a0

Please sign in to comment.