diff options
author | Slávek Banko <[email protected]> | 2022-03-22 02:40:43 +0100 |
---|---|---|
committer | Slávek Banko <[email protected]> | 2022-03-22 09:04:42 +0100 |
commit | 1bda8d37ecae1c41004b013600a4e8309a23136d (patch) | |
tree | dbdd397dca78825af091bb6b003414a8bd6c2ad4 | |
parent | af8acc4fc3ac3e4b0681077796ad831048674988 (diff) | |
download | qt3-1bda8d37ecae1c41004b013600a4e8309a23136d.tar.gz qt3-1bda8d37ecae1c41004b013600a4e8309a23136d.zip |
Avoid changes of d->cString for TQString::shared_null to make the value reliable.
This precedes unnecessary allocations, potential use after free and crashes.
Signed-off-by: Slávek Banko <[email protected]>
(cherry picked from commit 93058fb0a38cbab73683463cfa571fd622baa980)
-rw-r--r-- | src/tools/qstring.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/tools/qstring.cpp b/src/tools/qstring.cpp index 02d5cac..483efb9 100644 --- a/src/tools/qstring.cpp +++ b/src/tools/qstring.cpp @@ -5724,6 +5724,14 @@ const char* QString::ascii() const */ QCString QString::utf8() const { + if (!d->cString) { + d->cString = new QCString; + } + if(d == shared_null) + { + return *d->cString; + } + int l = length(); int rlen = l*3+1; QCString rstr(rlen); @@ -5768,11 +5776,8 @@ QCString QString::utf8() const ++ch; } rstr.truncate( cursor - (uchar*)rstr.data() ); - if (!d->cString) { - d->cString = new QCString; - } *d->cString = rstr; - return rstr; + return *d->cString; } static QChar *addOne(QChar *qch, QString &str) @@ -5971,6 +5976,10 @@ QCString QString::local8Bit() const if (!d->cString) { d->cString = new QCString; } + if(d == shared_null) + { + return *d->cString; + } #ifdef QT_NO_TEXTCODEC *d->cString = QCString(latin1()); return *d->cString; |