diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-10-15 08:48:21 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-10-15 07:08:06 +0000 |
commit | 9b0fcf7943e63f35cf7d13c7771cb0185178e9fa (patch) | |
tree | 2e39486ca2b80b0d525cdad24e0419521d982ace /src/3rdparty | |
parent | 42742b847213f7041fc686d7e15182c4669f897d (diff) | |
download | qtscript-9b0fcf7943e63f35cf7d13c7771cb0185178e9fa.tar.gz |
Never call an object with a this ptr that is nullv5.12.0-beta4v5.12.0-beta3
Task-number: QTBUG-67936
Change-Id: Ie12c87f8aef30ebca887ad357393c86417d7d742
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/3rdparty')
-rw-r--r-- | src/3rdparty/javascriptcore/JavaScriptCore/API/JSStringRef.cpp | 17 | ||||
-rw-r--r-- | src/3rdparty/javascriptcore/JavaScriptCore/API/OpaqueJSString.h | 4 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/API/JSStringRef.cpp b/src/3rdparty/javascriptcore/JavaScriptCore/API/JSStringRef.cpp index 8e236e4..fc337ef 100644 --- a/src/3rdparty/javascriptcore/JavaScriptCore/API/JSStringRef.cpp +++ b/src/3rdparty/javascriptcore/JavaScriptCore/API/JSStringRef.cpp @@ -67,18 +67,18 @@ void JSStringRelease(JSStringRef string) size_t JSStringGetLength(JSStringRef string) { - return string->length(); + return string ? string->length() : 0; } const JSChar* JSStringGetCharactersPtr(JSStringRef string) { - return string->characters(); + return string ? string->characters() : nullptr; } size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string) { // Any UTF8 character > 3 bytes encodes as a UTF16 surrogate pair. - return string->length() * 3 + 1; // + 1 for terminating '\0' + return string ? string->length() * 3 + 1 : 1; // + 1 for terminating '\0' } size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize) @@ -87,8 +87,11 @@ size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSiz return 0; char* p = buffer; - const UChar* d = string->characters(); - ConversionResult result = convertUTF16ToUTF8(&d, d + string->length(), &p, p + bufferSize - 1, true); + ConversionResult result = conversionOK; + if (string) { + const UChar* d = string->characters(); + result = convertUTF16ToUTF8(&d, d + string->length(), &p, p + bufferSize - 1, true); + } *p++ = '\0'; if (result != conversionOK && result != targetExhausted) return 0; @@ -98,6 +101,10 @@ size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSiz bool JSStringIsEqual(JSStringRef a, JSStringRef b) { + if (!a) + return (!b || b->length() == 0); + if (!b) + return (!a || a->length() == 0); unsigned len = a->length(); return len == b->length() && 0 == memcmp(a->characters(), b->characters(), len * sizeof(UChar)); } diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/API/OpaqueJSString.h b/src/3rdparty/javascriptcore/JavaScriptCore/API/OpaqueJSString.h index 473c815..6aa7b99 100644 --- a/src/3rdparty/javascriptcore/JavaScriptCore/API/OpaqueJSString.h +++ b/src/3rdparty/javascriptcore/JavaScriptCore/API/OpaqueJSString.h @@ -47,8 +47,8 @@ struct OpaqueJSString : public ThreadSafeShared<OpaqueJSString> { static PassRefPtr<OpaqueJSString> create(const JSC::UString&); - UChar* characters() { return this ? m_characters : 0; } - unsigned length() { return this ? m_length : 0; } + UChar* characters() { return m_characters; } + unsigned length() { return m_length; } JSC::UString ustring() const; JSC::Identifier identifier(JSC::JSGlobalData*) const; |