diff options
author | Manuel Klimek <klimek@google.com> | 2015-06-11 10:14:13 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2015-06-11 10:14:13 +0000 |
commit | f0c95b32ec314d94e952faf397c28c96df32e515 (patch) | |
tree | 98d532d59822c25e5836ce2b3c4677708b4d854e | |
parent | 6b0dcd7b8cd44576a1e8f3e5c70ae1235f1650c0 (diff) | |
download | bcm5719-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
-rw-r--r-- | clang/lib/Format/UnwrappedLineFormatter.cpp | 6 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 5 |
2 files changed, 8 insertions, 3 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); } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 5b3980bdb5f..46be32bf4b1 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -10576,7 +10576,10 @@ TEST_F(FormatTest, DisableRegions) { " int k;")); } -TEST_F(FormatTest, DoNotCrashOnInvalidInput) { format("? ) ="); } +TEST_F(FormatTest, DoNotCrashOnInvalidInput) { + format("? ) ="); + verifyNoCrash("#define a\\\n /**/}"); +} } // end namespace tooling } // end namespace clang |