Author: owenca
Date: 2022-06-07T15:28:03-07:00
New Revision: b5b33fbffb087f69f54b9a7bce70828ef6e82601

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

LOG: [clang-format] Skip parsing a block if it's nested too deep

Fixes #55912.

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

Added: 
    

Modified: 
    clang/lib/Format/UnwrappedLineParser.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 86b42c499b23b..aa1411d67799b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -842,6 +842,10 @@ void UnwrappedLineParser::parseBlock(bool 
MustBeDeclaration, unsigned AddLevels,
   unsigned InitialLevel = Line->Level;
   nextToken(/*LevelDifference=*/AddLevels);
 
+  // Bail out if there are too many levels. Otherwise, the stack might 
overflow.
+  if (Line->Level > 300)
+    return;
+
   if (MacroBlock && FormatTok->is(tok::l_paren))
     parseParens();
 


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

Reply via email to