r231066 - clang-format: Fix access to uninitialized memory.
Daniel Jasper
djasper at google.com
Tue Mar 3 05:59:50 PST 2015
Author: djasper
Date: Tue Mar 3 07:59:49 2015
New Revision: 231066
URL: http://llvm.org/viewvc/llvm-project?rev=231066&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=231066&r1=231065&r2=231066&view=diff
==============================================================================
--- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp Tue Mar 3 07:59:49 2015
@@ -232,6 +232,7 @@ void WhitespaceManager::alignEscapedNewl
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) {
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=231066&r1=231065&r2=231066&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Mar 3 07:59:49 2015
@@ -2656,6 +2656,10 @@ TEST_F(FormatTest, MacroDefinitionsWithI
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}");
More information about the cfe-commits
mailing list