summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2015-06-11 10:14:13 +0000
committerManuel Klimek <klimek@google.com>2015-06-11 10:14:13 +0000
commitf0c95b32ec314d94e952faf397c28c96df32e515 (patch)
tree98d532d59822c25e5836ce2b3c4677708b4d854e /clang/lib/Format
parent6b0dcd7b8cd44576a1e8f3e5c70ae1235f1650c0 (diff)
downloadbcm5719-llvm-f0c95b32ec314d94e952faf397c28c96df32e515.tar.gz
bcm5719-llvm-f0c95b32ec314d94e952faf397c28c96df32e515.zip
Fix crash in clang-format.
The following example used to crash clang-format. #define a\ /**/} Adjusting the indentation level cache for the line starting with the comment would lead to an out-of-bounds array read. llvm-svn: 239521
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index cbf8c6c9221..ee81b509d34 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -51,11 +51,13 @@ public:
/// next.
void nextLine(const AnnotatedLine &Line) {
Offset = getIndentOffset(*Line.First);
+ // Update the indent level cache size so that we can rely on it
+ // having the right size in adjustToUnmodifiedline.
+ while (IndentForLevel.size() <= Line.Level)
+ IndentForLevel.push_back(-1);
if (Line.InPPDirective) {
Indent = Line.Level * Style.IndentWidth + AdditionalIndent;
} else {
- while (IndentForLevel.size() <= Line.Level)
- IndentForLevel.push_back(-1);
IndentForLevel.resize(Line.Level + 1);
Indent = getIndent(IndentForLevel, Line.Level);
}
OpenPOWER on IntegriCloud