r242738 - clang-format: Fix crasher when a UTF8 character is found in an escape
Daniel Jasper
djasper at google.com
Mon Jul 20 16:28:07 PDT 2015
Author: djasper
Date: Mon Jul 20 18:28:07 2015
New Revision: 242738
URL: http://llvm.org/viewvc/llvm-project?rev=242738&view=rev
Log:
clang-format: Fix crasher when a UTF8 character is found in an escape
sequence. Discovered by the fuzzer.
Modified:
cfe/trunk/lib/Format/Encoding.h
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Encoding.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Encoding.h?rev=242738&r1=242737&r2=242738&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Encoding.h (original)
+++ cfe/trunk/lib/Format/Encoding.h Mon Jul 20 18:28:07 2015
@@ -135,7 +135,7 @@ inline unsigned getEscapeSequenceLength(
++I;
return I;
}
- return 2;
+ return 1 + getNumBytesForUTF8(Text[1]);
}
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=242738&r1=242737&r2=242738&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jul 20 18:28:07 2015
@@ -9555,6 +9555,11 @@ TEST_F(FormatTest, SplitsUTF8Strings) {
"\"å
«ä¹å\tqq\"",
format("\"ä¸\täº \tä¸ å äº\tå
\tä¸ å
«ä¹å\tqq\"",
getLLVMStyleWithColumns(11)));
+
+ // UTF8 character in an escape sequence.
+ EXPECT_EQ("\"aaaaaa\"\n"
+ "\"\\\xC2\x8D\"",
+ format("\"aaaaaa\\\xC2\x8D\"", getLLVMStyleWithColumns(10)));
}
TEST_F(FormatTest, HandlesDoubleWidthCharsInMultiLineStrings) {
More information about the cfe-commits
mailing list