diff options
author | Daniel Jasper <djasper@google.com> | 2015-03-03 13:59:49 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-03-03 13:59:49 +0000 |
commit | ace92c4e2bb94f3f8914588c94a91fe93c75d42f (patch) | |
tree | 6dd919e3b29aacd7d62f90aa8d917d9d18f66521 | |
parent | eb4587857f7386aad6a8ad083bda0f1e401f250d (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@231066 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Format/WhitespaceManager.cpp | 1 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 4 |
2 files changed, 5 insertions, 0 deletions
diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp index 44e5f690a2..fd5dd5991d 100644 --- a/lib/Format/WhitespaceManager.cpp +++ b/lib/Format/WhitespaceManager.cpp @@ -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) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index bfc601fb20..d49250391c 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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}"); |