Skip to content

Commit a2f9797

Browse files
authored
[Clang] Prevent null pointer dereference in Sema::​CodeCompleteQualifiedId() (#90490)
The null pointer dereference issue seems happening with in the expression NNS->getAsType(). Although dyn_cast_or_null<TemplateTypeParmType>() correctly handles null pointers, it doesn’t prevent the subsequent dereferencing operation. The fix ensures that NNS pointer is not null before calling the getAsType() method, thus preventing potential runtime errors caused by attempting to access a null pointer.
1 parent 7925525 commit a2f9797

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6714,14 +6714,16 @@ void Sema::CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
67146714

67156715
// If the scope is a concept-constrained type parameter, infer nested
67166716
// members based on the constraints.
6717-
if (const auto *TTPT =
6718-
dyn_cast_or_null<TemplateTypeParmType>(NNS->getAsType())) {
6719-
for (const auto &R : ConceptInfo(*TTPT, S).members()) {
6720-
if (R.Operator != ConceptInfo::Member::Colons)
6721-
continue;
6722-
Results.AddResult(CodeCompletionResult(
6723-
R.render(*this, CodeCompleter->getAllocator(),
6724-
CodeCompleter->getCodeCompletionTUInfo())));
6717+
if (NNS) {
6718+
if (const auto *TTPT =
6719+
dyn_cast_or_null<TemplateTypeParmType>(NNS->getAsType())) {
6720+
for (const auto &R : ConceptInfo(*TTPT, S).members()) {
6721+
if (R.Operator != ConceptInfo::Member::Colons)
6722+
continue;
6723+
Results.AddResult(CodeCompletionResult(
6724+
R.render(*this, CodeCompleter->getAllocator(),
6725+
CodeCompleter->getCodeCompletionTUInfo())));
6726+
}
67256727
}
67266728
}
67276729

0 commit comments

Comments
 (0)