From: Daniel Jasper Date: Wed, 21 Jan 2015 19:50:35 +0000 (+0000) Subject: clang-format: Fix crasher when splitting incomplete escape sequences. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3738afc3772111aa7aa87fe9332c4fc29482cb6e;p=clang clang-format: Fix crasher when splitting incomplete escape sequences. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226698 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/BreakableToken.cpp b/lib/Format/BreakableToken.cpp index 26f1371b40..c84d9afdd4 100644 --- a/lib/Format/BreakableToken.cpp +++ b/lib/Format/BreakableToken.cpp @@ -106,7 +106,7 @@ getStringSplit(StringRef Text, unsigned UsedColumns, unsigned ColumnLimit, 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])) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 553368d563..7c86d14a52 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -7444,6 +7444,12 @@ TEST_F(FormatTest, BreaksWideAndNSStringLiterals) { 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) {