[PATCH] D138371: [clang-format] Fix a crash due to dereferencing null MatchingParen
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 19 19:31:50 PST 2022
owenpan updated this revision to Diff 476719.
owenpan added a comment.
Added a test case.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138371/new/
https://reviews.llvm.org/D138371
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -26065,6 +26065,8 @@
"}",
Style);
+ verifyIncompleteFormat("class C final [[deprecated(l]] {});", Style);
+
// These tests are here to show a problem that may not be easily
// solved, our implementation to remove semicolons is only as good
// as our FunctionLBrace detection and this fails for empty braces
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2852,6 +2852,8 @@
return false;
} else if (isCppAttribute(IsCpp, *Next)) {
Next = Next->MatchingParen;
+ if (!Next)
+ return false;
} else if (Next->is(tok::l_paren)) {
break;
} else {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138371.476719.patch
Type: text/x-patch
Size: 997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221120/2361bd28/attachment-0001.bin>
More information about the cfe-commits
mailing list