r226698 - clang-format: Fix crasher when splitting incomplete escape sequences.
Daniel Jasper
djasper at google.com
Wed Jan 21 11:50:35 PST 2015
Author: djasper
Date: Wed Jan 21 13:50:35 2015
New Revision: 226698
URL: http://llvm.org/viewvc/llvm-project?rev=226698&view=rev
Log:
clang-format: Fix crasher when splitting incomplete escape sequences.
Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=226698&r1=226697&r2=226698&view=diff
==============================================================================
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Wed Jan 21 13:50:35 2015
@@ -106,7 +106,7 @@ getStringSplit(StringRef Text, unsigned
Text.substr(0, Advance), UsedColumns + Chars, TabWidth, Encoding);
}
- if (Chars > MaxSplit || Text.size() == Advance)
+ if (Chars > MaxSplit || Text.size() <= Advance)
break;
if (IsBlank(Text[0]))
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=226698&r1=226697&r2=226698&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan 21 13:50:35 2015
@@ -7444,6 +7444,12 @@ TEST_F(FormatTest, BreaksWideAndNSString
EXPECT_EQ("@\"NSString \"\n"
"@\"literal\";",
format("@\"NSString literal\";", getGoogleStyleWithColumns(19)));
+
+ // This input makes clang-format try to split the incomplete unicode escape
+ // sequence, which used to lead to a crasher.
+ verifyNoCrash(
+ "aaaaaaaaaaaaaaaaaaaa = L\"\\udff\"'; // aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ getLLVMStyleWithColumns(60));
}
TEST_F(FormatTest, DoesNotBreakRawStringLiterals) {
More information about the cfe-commits
mailing list