]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - wtf/text/CString.cpp
JavaScriptCore-903.tar.gz
[apple/javascriptcore.git] / wtf / text / CString.cpp
index 3ce3053eaed67c58f1c4a33d332e4d6c0ff62358..981d77a1db2e456faad927efe29a0641015fad37 100644 (file)
@@ -33,21 +33,27 @@ namespace WTF {
 
 CString::CString(const char* str)
 {
+    if (!str)
+        return;
+
     init(str, strlen(str));
 }
 
-CString::CString(const char* str, unsigned length)
+CString::CString(const char* str, size_t length)
 {
     init(str, length);
 }
 
-void CString::init(const char* str, unsigned length)
+void CString::init(const char* str, size_t length)
 {
     if (!str)
         return;
 
-    if (length >= numeric_limits<size_t>::max())
-        CRASH();
+    // We need to be sure we can add 1 to length without overflowing.
+    // Since the passed-in length is the length of an actual existing
+    // string, and we know the string doesn't occupy the entire address
+    // space, we can assert here and there's no need for a runtime check.
+    ASSERT(length < numeric_limits<size_t>::max());
 
     m_buffer = CStringBuffer::create(length + 1);
     memcpy(m_buffer->mutableData(), str, length);