From 0640dce6cd3200979a9b98d5bbae4526fc6dcec8 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 7 May 2014 13:51:26 +0200 Subject: Fix crash on host/target word size mismatches When compiling on a 64-bit host and using the QV4::CompileData on a 32-bit target, the size of QArrayData is different. Therefore we cannot use it in the QV4::CompiledData and have to resort to storing only the characters in there. We can at least still use fromRawData when extracting strings, but the QStringData will have to be allocated now. Change-Id: Ia9dab1722ed72186451b65ba74457051c6ce3155 Reviewed-by: Lars Knoll --- src/qml/compiler/qv4compileddata_p.h | 11 +++++------ src/qml/compiler/qv4compiler.cpp | 6 +----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h index 1fba6c0d3c..6ee23690a6 100644 --- a/src/qml/compiler/qv4compileddata_p.h +++ b/src/qml/compiler/qv4compileddata_p.h @@ -151,7 +151,7 @@ struct JSClass struct String { quint32 flags; // isArrayIndex - QArrayData str; + qint32 size; // uint16 strdata[] static int calculateSize(const QString &str) { @@ -195,13 +195,12 @@ struct Unit const uint *offsetTable = reinterpret_cast((reinterpret_cast(this)) + offsetToStringTable); const uint offset = offsetTable[idx]; const String *str = reinterpret_cast(reinterpret_cast(this) + offset); - if (str->str.size == 0) + if (str->size == 0) return QString(); - QStringDataPtr holder = { const_cast(static_cast(&str->str)) }; - QString qstr(holder); + const QChar *characters = reinterpret_cast(str + 1); if (flags & StaticData) - return qstr; - return QString(qstr.constData(), qstr.length()); + return QString::fromRawData(characters, str->size); + return QString(characters, str->size); } const uint *functionOffsetTable() const { return reinterpret_cast((reinterpret_cast(this)) + offsetToFunctionTable); } diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp index 65ef5c4b5e..144ef8a79e 100644 --- a/src/qml/compiler/qv4compiler.cpp +++ b/src/qml/compiler/qv4compiler.cpp @@ -82,11 +82,7 @@ void QV4::Compiler::StringTableGenerator::serialize(uint *stringTable, char *dat QV4::CompiledData::String *s = (QV4::CompiledData::String*)(stringData); s->flags = 0; // ### - s->str.ref.atomic.store(-1); - s->str.size = qstr.length(); - s->str.alloc = 0; - s->str.capacityReserved = false; - s->str.offset = sizeof(QArrayData); + s->size = qstr.length(); memcpy(s + 1, qstr.constData(), (qstr.length() + 1)*sizeof(ushort)); stringData += QV4::CompiledData::String::calculateSize(qstr); -- cgit v1.2.3