[clang] 4daeb8c - [clang-format] Fix a crash due to dereferencing null MatchingParen

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 21 12:33:59 PST 2022


Author: Owen Pan
Date: 2022-11-21T12:33:51-08:00
New Revision: 4daeb8c7335439e2ab43d66acfed087c417a7314

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

LOG: [clang-format] Fix a crash due to dereferencing null MatchingParen

Fixes #59089.

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

Added: 
    

Modified: 
    clang/lib/Format/TokenAnnotator.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 21152b8c20e11..7f16d04d898b9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2851,6 +2851,8 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
           return false;
       } else if (isCppAttribute(IsCpp, *Next)) {
         Next = Next->MatchingParen;
+        if (!Next)
+          return false;
       } else if (Next->is(tok::l_paren)) {
         break;
       } else {

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index d4150f46d1f58..1db8ee94369b7 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25017,6 +25017,8 @@ TEST_F(FormatTest, RemoveSemicolon) {
                "}",
                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


        


More information about the cfe-commits mailing list