Author: Paul Kirth
Date: 2022-07-22T17:36:30Z
New Revision: 30360d88d42214e75215145c4e73a74aaf93ddfd

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

LOG: [clang-doc] Add check for pointer validity

clang-doc would SEGV when running over the Fuchsia code base.
This patch adds a check to avoid dereferencing potentially null pointers
in the Values vector. These pointers were either never valid or had been
invalidated when the underlying pointer in std::unique_ptr was moved from,
hence making it nullptr within the vector.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D130279

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-doc/Representation.cpp 
b/clang-tools-extra/clang-doc/Representation.cpp
index 8c619d2a09632..0a78d8c190db9 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -33,7 +33,7 @@ const SymbolID EmptySID = SymbolID();
 template <typename T>
 llvm::Expected<std::unique_ptr<Info>>
 reduce(std::vector<std::unique_ptr<Info>> &Values) {
-  if (Values.empty())
+  if (Values.empty() || !Values[0])
     return llvm::createStringError(llvm::inconvertibleErrorCode(),
                                    "no value to reduce");
   std::unique_ptr<Info> Merged = std::make_unique<T>(Values[0]->USR);
@@ -95,7 +95,7 @@ void reduceChildren(std::vector<EnumInfo> &Children,
 // Dispatch function.
 llvm::Expected<std::unique_ptr<Info>>
 mergeInfos(std::vector<std::unique_ptr<Info>> &Values) {
-  if (Values.empty())
+  if (Values.empty() || !Values[0])
     return llvm::createStringError(llvm::inconvertibleErrorCode(),
                                    "no info values to merge");
 


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to