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
This commit is contained in:
Manuel Klimek 2015-06-11 10:14:13 +00:00
parent 6b0dcd7b8c
commit f0c95b32ec
2 changed files with 8 additions and 3 deletions

View File

@ -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);
}

View File

@ -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