summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2019-02-10 11:25:02 +0100
committerSlávek Banko <slavek.banko@axis.cz>2019-02-10 11:25:22 +0100
commit5a7d49f513197ca7dbf3696c744151c7d120fe32 (patch)
treeb562fb351a3fba41319e70c503f260050668f1d4 /src
parent872d13f1ae7cced7d8bd8813680def5c0b1eb65d (diff)
downloadqt3-5a7d49f513197ca7dbf3696c744151c7d120fe32.tar.gz
qt3-5a7d49f513197ca7dbf3696c744151c7d120fe32.zip
Make use of QString::utf8() and QString::local8Bit() safe for conversion to char*.
Signed-off-by: Slávek Banko <slavek.banko@axis.cz> (cherry picked from commit 0a1966b25e36fbca6263b656fec8de9d42770f8d)
Diffstat (limited to 'src')
-rw-r--r--src/tools/qstring.cpp34
-rw-r--r--src/tools/qstring.h1
2 files changed, 27 insertions, 8 deletions
diff --git a/src/tools/qstring.cpp b/src/tools/qstring.cpp
index 1c796fe..5bb3761 100644
--- a/src/tools/qstring.cpp
+++ b/src/tools/qstring.cpp
@@ -1051,7 +1051,8 @@ QStringData::QStringData() : QShared(),
issimpletext(TRUE),
maxl(0),
islatin1(FALSE),
- security_unpaged(FALSE) {
+ security_unpaged(FALSE),
+ cString(0) {
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
mutex = new QMutex(FALSE);
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
@@ -1065,7 +1066,8 @@ QStringData::QStringData(QChar *u, uint l, uint m) : QShared(),
issimpletext(FALSE),
maxl(m),
islatin1(FALSE),
- security_unpaged(FALSE) {
+ security_unpaged(FALSE),
+ cString(0) {
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
mutex = new QMutex(FALSE);
#endif // QT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE
@@ -1083,6 +1085,9 @@ QStringData::~QStringData() {
if ( ascii ) {
delete[] ascii;
}
+ if (cString) {
+ delete cString;
+ }
#if defined(QT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE)
if ( mutex ) {
delete mutex;
@@ -1096,6 +1101,10 @@ void QStringData::setDirty() {
delete [] ascii;
ascii = 0;
}
+ if (cString) {
+ delete cString;
+ cString = 0;
+ }
issimpletext = FALSE;
}
@@ -6026,6 +6035,10 @@ QCString QString::utf8() const
++ch;
}
rstr.truncate( cursor - (uchar*)rstr.data() );
+ if (!d->cString) {
+ d->cString = new QCString;
+ }
+ *d->cString = rstr;
return rstr;
}
@@ -6227,23 +6240,28 @@ QString QString::fromLatin1( const char* chars, int len )
QCString QString::local8Bit() const
{
+ if (!d->cString) {
+ d->cString = new QCString;
+ }
#ifdef QT_NO_TEXTCODEC
- return latin1();
+ *d->cString = QCString(latin1());
+ return *d->cString;
#else
#ifdef Q_WS_X11
QTextCodec* codec = QTextCodec::codecForLocale();
- return codec
- ? codec->fromUnicode(*this)
- : QCString(latin1());
+ *d->cString = codec ? codec->fromUnicode(*this) : QCString(latin1());
+ return *d->cString;
#endif
#if defined( Q_WS_MACX )
return utf8();
#endif
#if defined( Q_WS_MAC9 )
- return QCString(latin1()); //I'm evil..
+ *d->cString = QCString(latin1()); //I'm evil..
+ return *d->cString;
#endif
#ifdef Q_WS_WIN
- return isNull() ? QCString("") : qt_winQString2MB( *this );
+ *d->cString = isNull() ? QCString("") : qt_winQString2MB( *this );
+ return *d->cString;
#endif
#ifdef Q_WS_QWS
return utf8(); // ### if there is any 8 bit format supported?
diff --git a/src/tools/qstring.h b/src/tools/qstring.h
index 8715395..4c40ce8 100644
--- a/src/tools/qstring.h
+++ b/src/tools/qstring.h
@@ -384,6 +384,7 @@ struct Q_EXPORT QStringData : public QShared {
bool security_unpaged : 1;
QMutex* mutex;
+ QCString *cString;
private:
#if defined(Q_DISABLE_COPY)