-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[clang-doc] Avoid deref of invalid std::optional #131939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes the crashes I was experiencing.
@llvm/pr-subscribers-clang-tools-extra Author: Paul Kirth (ilovepi) ChangesSince our existing guard is insufficient to prevent accessing the The new test should prevent regressions. Fixes #131697 Full diff: https://github.com/llvm/llvm-project/pull/131939.diff 2 Files Affected:
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 18a0de826630c..a8404479569f9 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -498,7 +498,7 @@ writeFileDefinition(const Location &L,
return std::make_unique<TagNode>(
HTMLTag::TAG_P, "Defined at line " + std::to_string(L.LineNumber) +
" of file " + L.Filename);
- SmallString<128> FileURL(*RepositoryUrl);
+ SmallString<128> FileURL(RepositoryUrl.value_or(""));
llvm::sys::path::append(
FileURL, llvm::sys::path::Style::posix,
// If we're on Windows, the file name will be in the wrong format, and
diff --git a/clang-tools-extra/test/clang-doc/DR-131697.cpp b/clang-tools-extra/test/clang-doc/DR-131697.cpp
new file mode 100644
index 0000000000000..50556ecd2635b
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/DR-131697.cpp
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: split-file %s %t
+// RUN: clang-doc -format=html %t/compile-commands.json %t/main.cpp
+
+//--- main.cpp
+
+class Foo {
+ void getFoo();
+};
+
+int main() {
+ return 0;
+}
+
+//--- compile-commands.json
+[
+{
+ "directory": "foo",
+ "file":"main.cpp",
+ "command":"clang main.cpp -c"
+}
+]
|
03e1275
to
5a6bdbc
Compare
2de1ac2
to
ea33858
Compare
bc2b1ec
to
215f9a3
Compare
Since our existing guard is insufficient to prevent accessing the std::optional when in an invalid state, guard the access with `.value_or()`. This maintains the desired behavior, without running into UB. The new test should prevent regressions. Fixes #131697
215f9a3
to
b1653a1
Compare
Since our existing guard is insufficient to prevent accessing the
std::optional when in an invalid state, guard the access with
.value_or()
. This maintains the desired behavior, without running intoUB.
The new test should prevent regressions.
Fixes #131697