From 292a953258cac0107b820490b09231c0f700bdbe Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Thu, 9 Jun 2011 17:34:16 +0200 Subject: make the previous change foolproof in order to preserve the old behavior in a (corner) case where string was created from the raw data with a shorter lifecycle, just call QString's realloc() that will copy the data and thus guarantee it's consistence later. example: QCFString str; { QString qstr("I'm stupid"); str = QCFString(QString::fromRawData(qstr.data(), qstr.size()); } Merge-request: 2615 Reviewed-by: Denis Dzyubenko --- src/corelib/kernel/qcore_mac.cpp | 2 ++ src/corelib/tools/qstring.h | 1 + 2 files changed, 3 insertions(+) diff --git a/src/corelib/kernel/qcore_mac.cpp b/src/corelib/kernel/qcore_mac.cpp index 80cbac9..e45ef50 100644 --- a/src/corelib/kernel/qcore_mac.cpp +++ b/src/corelib/kernel/qcore_mac.cpp @@ -75,6 +75,8 @@ CFStringRef QCFString::toCFStringRef(const QString &string) QCFString::operator CFStringRef() const { if (!type) { + if (string.d->data != string.d->array) + const_cast(this)->string.realloc(); // ### Qt5: do we really need this stupid user protection? const_cast(this)->type = CFStringCreateWithCharactersNoCopy(0, reinterpret_cast(string.unicode()), diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index c61d09e..bf0a0ad 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -639,6 +639,7 @@ private: static Data *fromAscii_helper(const char *str, int size = -1); void replace_helper(uint *indices, int nIndices, int blen, const QChar *after, int alen); friend class QCharRef; + friend class QCFString; friend class QTextCodec; friend class QStringRef; friend struct QAbstractConcatenable; -- cgit v0.12