]> granicus.if.org Git - clang/commitdiff
clang-format: Fix access to uninitialized memory.
authorDaniel Jasper <djasper@google.com>
Tue, 3 Mar 2015 13:59:49 +0000 (13:59 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 3 Mar 2015 13:59:49 +0000 (13:59 +0000)
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

lib/Format/WhitespaceManager.cpp
unittests/Format/FormatTest.cpp

index 44e5f690a2630aa13d6f29c89aca2d23cbf3477f..fd5dd5991da0835b6a249f4d33919c279578c86c 100644 (file)
@@ -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) {
index bfc601fb2035935c3a888620225591905cc18f43..d49250391c5028101edfb52c941e5dfaeef8f1f5 100644 (file)
@@ -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}");