[clang] a2f9797 - [Clang] Prevent null pointer dereference in Sema::​CodeCompleteQualifiedId() (#90490)

via cfe-commits cfe-commits at lists.llvm.org
Thu May 2 06:22:24 PDT 2024


Author: smanna12
Date: 2024-05-02T08:22:20-05:00
New Revision: a2f97974e670379b28f7ad4701233fc162a46867

URL: https://github.com/llvm/llvm-project/commit/a2f97974e670379b28f7ad4701233fc162a46867
DIFF: https://github.com/llvm/llvm-project/commit/a2f97974e670379b28f7ad4701233fc162a46867.diff

LOG: [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.

Added: 
    

Modified: 
    clang/lib/Sema/SemaCodeComplete.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index c335017f243eb2..3f0ab10646fe5d 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -6714,14 +6714,16 @@ void Sema::CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
 
   // If the scope is a concept-constrained type parameter, infer nested
   // members based on the constraints.
-  if (const auto *TTPT =
-          dyn_cast_or_null<TemplateTypeParmType>(NNS->getAsType())) {
-    for (const auto &R : ConceptInfo(*TTPT, S).members()) {
-      if (R.Operator != ConceptInfo::Member::Colons)
-        continue;
-      Results.AddResult(CodeCompletionResult(
-          R.render(*this, CodeCompleter->getAllocator(),
-                   CodeCompleter->getCodeCompletionTUInfo())));
+  if (NNS) {
+    if (const auto *TTPT =
+            dyn_cast_or_null<TemplateTypeParmType>(NNS->getAsType())) {
+      for (const auto &R : ConceptInfo(*TTPT, S).members()) {
+        if (R.Operator != ConceptInfo::Member::Colons)
+          continue;
+        Results.AddResult(CodeCompletionResult(
+            R.render(*this, CodeCompleter->getAllocator(),
+                     CodeCompleter->getCodeCompletionTUInfo())));
+      }
     }
   }
 


        


More information about the cfe-commits mailing list