Title: [127093] trunk
Revision
127093
Author
[email protected]
Date
2012-08-29 20:56:13 -0700 (Wed, 29 Aug 2012)

Log Message

REGRESSION(r126780): Crash using StringImpl::is8Bit before checking if there is an impl
https://bugs.webkit.org/show_bug.cgi?id=95380

Patch by Benjamin Poulain <[email protected]> on 2012-08-29
Reviewed by Michael Saboff.

Source/WTF:

Blindly copying code from UString in r126780 was stupid. I just brought over a bug.
This patch adds the zero length branch back so that null strings are handled correctly.

* wtf/text/WTFString.cpp:
(WTF::String::ascii): Return a empty CString if the String is null or empty.

Tools:

* TestWebKitAPI/Tests/WTF/WTFString.cpp:
Add very basic tests for String::ascii(). This covers the case of null strings that caused
the crash.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (127092 => 127093)


--- trunk/Source/WTF/ChangeLog	2012-08-30 03:48:29 UTC (rev 127092)
+++ trunk/Source/WTF/ChangeLog	2012-08-30 03:56:13 UTC (rev 127093)
@@ -1,3 +1,16 @@
+2012-08-29  Benjamin Poulain  <[email protected]>
+
+        REGRESSION(r126780): Crash using StringImpl::is8Bit before checking if there is an impl
+        https://bugs.webkit.org/show_bug.cgi?id=95380
+
+        Reviewed by Michael Saboff.
+
+        Blindly copying code from UString in r126780 was stupid. I just brought over a bug.
+        This patch adds the zero length branch back so that null strings are handled correctly.
+
+        * wtf/text/WTFString.cpp:
+        (WTF::String::ascii): Return a empty CString if the String is null or empty.
+
 2012-08-29  Dominik Röttsches  <[email protected]>
 
         The 2d.imageData.object.round canvas test is failing

Modified: trunk/Source/WTF/wtf/text/WTFString.cpp (127092 => 127093)


--- trunk/Source/WTF/wtf/text/WTFString.cpp	2012-08-30 03:48:29 UTC (rev 127092)
+++ trunk/Source/WTF/wtf/text/WTFString.cpp	2012-08-30 03:56:13 UTC (rev 127093)
@@ -609,6 +609,10 @@
     // preserved, characters outside of this range are converted to '?'.
 
     unsigned length = this->length();
+    if (!length) { 
+        char* characterBuffer;
+        return CString::newUninitialized(length, characterBuffer);
+    }
 
     if (this->is8Bit()) {
         const LChar* characters = this->characters8();

Modified: trunk/Tools/ChangeLog (127092 => 127093)


--- trunk/Tools/ChangeLog	2012-08-30 03:48:29 UTC (rev 127092)
+++ trunk/Tools/ChangeLog	2012-08-30 03:56:13 UTC (rev 127093)
@@ -1,3 +1,14 @@
+2012-08-29  Benjamin Poulain  <[email protected]>
+
+        REGRESSION(r126780): Crash using StringImpl::is8Bit before checking if there is an impl
+        https://bugs.webkit.org/show_bug.cgi?id=95380
+
+        Reviewed by Michael Saboff.
+
+        * TestWebKitAPI/Tests/WTF/WTFString.cpp:
+        Add very basic tests for String::ascii(). This covers the case of null strings that caused
+        the crash.
+
 2012-08-29  Dominic Mazzoni  <[email protected]>
 
         AX: Canvas should have a distinct role

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp (127092 => 127093)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp	2012-08-30 03:48:29 UTC (rev 127092)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp	2012-08-30 03:56:13 UTC (rev 127093)
@@ -49,6 +49,23 @@
     ASSERT_TRUE(String("Template Literal") == stringWithTemplate);
 }
 
+TEST(WTF, StringASCII)
+{
+    CString output;
+
+    // Null String.
+    output = String().ascii();
+    ASSERT_STREQ("", output.data());
+
+    // Empty String.
+    output = emptyString().ascii();
+    ASSERT_STREQ("", output.data());
+
+    // Regular String.
+    output = String(ASCIILiteral("foobar")).ascii();
+    ASSERT_STREQ("foobar", output.data());
+}
+
 static void testNumberToStringECMAScript(double number, const char* reference)
 {
     CString numberString = String::numberToStringECMAScript(number).latin1();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to