clang-format: Fix access to uninitialized memory.
With incomplete code, we aren't guaranteed to generated changes for every token. In that case, we need to assume that even the very first change can continue a preprocessor directive and initialize values accordingly. llvm-svn: 231066
This commit is contained in:
parent
bd05108e53
commit
0391e55650
|
@ -232,6 +232,7 @@ void WhitespaceManager::alignEscapedNewlines() {
|
|||
unsigned MaxEndOfLine =
|
||||
Style.AlignEscapedNewlinesLeft ? 0 : Style.ColumnLimit;
|
||||
unsigned StartOfMacro = 0;
|
||||
Changes[0].EscapedNewlineColumn = 0;
|
||||
for (unsigned i = 1, e = Changes.size(); i < e; ++i) {
|
||||
Change &C = Changes[i];
|
||||
if (C.NewlinesBefore > 0) {
|
||||
|
|
|
@ -2656,6 +2656,10 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) {
|
|||
getLLVMStyleWithColumns(28));
|
||||
verifyFormat("#d, = };");
|
||||
verifyFormat("#if \"a");
|
||||
verifyFormat("({\n"
|
||||
"#define b }\\\n"
|
||||
" a\n"
|
||||
"a");
|
||||
|
||||
verifyNoCrash("#if a\na(\n#else\n#endif\n{a");
|
||||
verifyNoCrash("a={0,1\n#if a\n#else\n;\n#endif\n}");
|
||||
|
|
Loading…
Reference in New Issue