diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-01-22 12:28:43 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-01-22 14:27:52 +0000 |
commit | c4f1a676fcaad76829c7cda1f5bea018150b7412 (patch) | |
tree | 1efbe8ab0f7ee33a36900824b145e7f5cf14b393 | |
parent | 1ab5d14615f713a87141b66675521d702542d3a6 (diff) |
Fix crash in tst_controls in QQC2
Handle startsWithUpper() for complex sub-strings
Change-Id: Ia7494a880612761ee3caf9113c2ac5faa4edd182
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/qml/jsruntime/qv4string.cpp | 21 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4string_p.h | 7 |
2 files changed, 24 insertions, 4 deletions
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<const Heap::ComplexString *>(this)->left->startsWithUpper(); + + const Heap::String *str = this; + int offset = 0; + if (subtype == StringType_SubString) { + const ComplexString *cs = static_cast<const Heap::ComplexString *>(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<const String *> 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; } |