From c4f1a676fcaad76829c7cda1f5bea018150b7412 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 22 Jan 2018 12:28:43 +0100 Subject: Fix crash in tst_controls in QQC2 Handle startsWithUpper() for complex sub-strings Change-Id: Ia7494a880612761ee3caf9113c2ac5faa4edd182 Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4string.cpp | 21 +++++++++++++++++++++ src/qml/jsruntime/qv4string_p.h | 7 +++---- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src/qml') diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp index 932ccf13ef..40280534c4 100644 --- a/src/qml/jsruntime/qv4string.cpp +++ b/src/qml/jsruntime/qv4string.cpp @@ -181,6 +181,27 @@ void Heap::String::simplifyString() const subtype = StringType_Unknown; } +bool Heap::String::startsWithUpper() const +{ + if (subtype == StringType_AddedString) + return static_cast(this)->left->startsWithUpper(); + + const Heap::String *str = this; + int offset = 0; + if (subtype == StringType_SubString) { + const ComplexString *cs = static_cast(this); + if (!cs->len) + return false; + // simplification here is not ideal, but hopefully not a common case. + if (cs->left->subtype >= Heap::String::StringType_Complex) + cs->left->simplifyString(); + str = cs->left; + offset = cs->from; + } + Q_ASSERT(str->subtype < Heap::String::StringType_Complex); + return str->text->size > offset && QChar::isUpper(str->text->data()[offset]); +} + void Heap::String::append(const String *data, QChar *ch) { std::vector worklist; diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h index 41039bca88..679cb7329c 100644 --- a/src/qml/jsruntime/qv4string_p.h +++ b/src/qml/jsruntime/qv4string_p.h @@ -112,6 +112,8 @@ struct Q_QML_PRIVATE_EXPORT String : Base { return toQString() == other->toQString(); } + bool startsWithUpper() const; + mutable QStringData *text; mutable Identifier *identifier; mutable uint subtype; @@ -206,10 +208,7 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed { return calculateHashValue(ch, end, subtype); } - bool startsWithUpper() const { - Q_ASSERT(d()->subtype < Heap::String::StringType_Complex); - return d()->text->size && QChar::isUpper(d()->text->data()[0]); - } + bool startsWithUpper() const { return d()->startsWithUpper(); } Identifier *identifier() const { return d()->identifier; } -- cgit v1.2.3