[PATCH] D130279: [clang-doc] Add check for pointer validity
Paul Kirth via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 21 08:19:18 PDT 2022
paulkirth created this revision.
paulkirth added reviewers: phosek, abrachet.
Herald added a project: All.
paulkirth requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D130279
Files:
clang-tools-extra/clang-doc/Representation.cpp
Index: clang-tools-extra/clang-doc/Representation.cpp
===================================================================
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -33,7 +33,7 @@
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 @@
// 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");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130279.446512.patch
Type: text/x-patch
Size: 948 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220721/31ec8fcc/attachment.bin>
More information about the cfe-commits
mailing list