[clang-tools-extra] c4eef9e - [clang-doc] Fix nullptr dereference in JSONGenerator::insertComment (#173336)

via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 22 23:00:15 PST 2025


Author: Erick Velez
Date: 2025-12-22T23:00:11-08:00
New Revision: c4eef9e13fc3527c4e3364f552bedaf02158e4fb

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

LOG: [clang-doc] Fix nullptr dereference in JSONGenerator::insertComment (#173336)

The `if` statements in `insertComment` didn't check whether or not the
comment JSON object was a nullptr before dereferencing it. This crash
only happened when running clang-doc on larger codebases, like `clang`.

Added: 
    

Modified: 
    clang-tools-extra/clang-doc/JSONGenerator.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 9c384ed7eeade..6dec347ed0bd0 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -98,11 +98,12 @@ static void insertComment(Object &Description, json::Value &Comment,
   // The comment has a Children array for the actual text, with meta attributes
   // alongside it in the Object.
   if (auto *Obj = Comment.getAsObject()) {
-    if (auto *Children = Obj->getArray("Children"); Children->empty())
+    if (auto *Children = Obj->getArray("Children");
+        Children && Children->empty())
       return;
   }
   // The comment is just an array of text comments.
-  else if (auto *Array = Comment.getAsArray(); Array->empty()) {
+  else if (auto *Array = Comment.getAsArray(); Array && Array->empty()) {
     return;
   }
 


        


More information about the cfe-commits mailing list