summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/wtf/text
diff options
context:
space:
mode:
Diffstat (limited to 'JavaScriptCore/wtf/text')
-rw-r--r--JavaScriptCore/wtf/text/CString.cpp7
-rw-r--r--JavaScriptCore/wtf/text/StringImpl.cpp9
-rw-r--r--JavaScriptCore/wtf/text/StringImpl.h5
3 files changed, 16 insertions, 5 deletions
diff --git a/JavaScriptCore/wtf/text/CString.cpp b/JavaScriptCore/wtf/text/CString.cpp
index db6443f..981d77a 100644
--- a/JavaScriptCore/wtf/text/CString.cpp
+++ b/JavaScriptCore/wtf/text/CString.cpp
@@ -49,8 +49,11 @@ 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);
diff --git a/JavaScriptCore/wtf/text/StringImpl.cpp b/JavaScriptCore/wtf/text/StringImpl.cpp
index 1c4de66..c83ec42 100644
--- a/JavaScriptCore/wtf/text/StringImpl.cpp
+++ b/JavaScriptCore/wtf/text/StringImpl.cpp
@@ -270,12 +270,17 @@ PassRefPtr<StringImpl> StringImpl::upper()
return newImpl.release();
}
-PassRefPtr<StringImpl> StringImpl::secure(UChar character)
+PassRefPtr<StringImpl> StringImpl::secure(UChar character, LastCharacterBehavior behavior)
{
+ if (!m_length)
+ return this;
+
UChar* data;
RefPtr<StringImpl> newImpl = createUninitialized(m_length, data);
- for (unsigned i = 0; i < m_length; ++i)
+ unsigned lastCharacterIndex = m_length - 1;
+ for (unsigned i = 0; i < lastCharacterIndex; ++i)
data[i] = character;
+ data[lastCharacterIndex] = (behavior == ObscureLastCharacter) ? character : m_data[lastCharacterIndex];
return newImpl.release();
}
diff --git a/JavaScriptCore/wtf/text/StringImpl.h b/JavaScriptCore/wtf/text/StringImpl.h
index 8f0af52..99d0e9d 100644
--- a/JavaScriptCore/wtf/text/StringImpl.h
+++ b/JavaScriptCore/wtf/text/StringImpl.h
@@ -284,7 +284,10 @@ public:
PassRefPtr<StringImpl> lower();
PassRefPtr<StringImpl> upper();
- PassRefPtr<StringImpl> secure(UChar aChar);
+
+ enum LastCharacterBehavior { ObscureLastCharacter, DisplayLastCharacter };
+
+ PassRefPtr<StringImpl> secure(UChar, LastCharacterBehavior = ObscureLastCharacter);
PassRefPtr<StringImpl> foldCase();
PassRefPtr<StringImpl> stripWhiteSpace();