diff options
author | Russell Brenner <russellbrenner@google.com> | 2010-11-18 17:33:13 -0800 |
---|---|---|
committer | Russell Brenner <russellbrenner@google.com> | 2010-12-02 13:47:21 -0800 |
commit | 6b70adc33054f8aee8c54d0f460458a9df11b8a5 (patch) | |
tree | 103a13998c33944d6ab3b8318c509a037e639460 /JavaScriptCore/wtf/text/CString.cpp | |
parent | bdf4ebc8e70b2d221b6ee7a65660918ecb1d33aa (diff) | |
download | external_webkit-6b70adc33054f8aee8c54d0f460458a9df11b8a5.zip external_webkit-6b70adc33054f8aee8c54d0f460458a9df11b8a5.tar.gz external_webkit-6b70adc33054f8aee8c54d0f460458a9df11b8a5.tar.bz2 |
Merge WebKit at r72274: Initial merge by git.
Change-Id: Ie51f0b4a16da82942bd516dce59cfb79ebbe25fb
Diffstat (limited to 'JavaScriptCore/wtf/text/CString.cpp')
-rw-r--r-- | JavaScriptCore/wtf/text/CString.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/JavaScriptCore/wtf/text/CString.cpp b/JavaScriptCore/wtf/text/CString.cpp index c048a1b..db6443f 100644 --- a/JavaScriptCore/wtf/text/CString.cpp +++ b/JavaScriptCore/wtf/text/CString.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003, 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,12 +27,15 @@ #include "config.h" #include "CString.h" -using std::min; +using namespace std; namespace WTF { CString::CString(const char* str) { + if (!str) + return; + init(str, strlen(str)); } @@ -45,7 +48,10 @@ void CString::init(const char* str, size_t length) { if (!str) return; - + + if (length >= numeric_limits<size_t>::max()) + CRASH(); + m_buffer = CStringBuffer::create(length + 1); memcpy(m_buffer->mutableData(), str, length); m_buffer->mutableData()[length] = '\0'; @@ -61,6 +67,9 @@ char* CString::mutableData() CString CString::newUninitialized(size_t length, char*& characterBuffer) { + if (length >= numeric_limits<size_t>::max()) + CRASH(); + CString result; result.m_buffer = CStringBuffer::create(length + 1); char* bytes = result.m_buffer->mutableData(); @@ -73,11 +82,11 @@ void CString::copyBufferIfNeeded() { if (!m_buffer || m_buffer->hasOneRef()) return; - - int len = m_buffer->length(); - RefPtr<CStringBuffer> m_temp = m_buffer; - m_buffer = CStringBuffer::create(len); - memcpy(m_buffer->mutableData(), m_temp->data(), len); + + RefPtr<CStringBuffer> buffer = m_buffer.release(); + size_t length = buffer->length(); + m_buffer = CStringBuffer::create(length); + memcpy(m_buffer->mutableData(), buffer->data(), length); } bool operator==(const CString& a, const CString& b) |