summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2022-03-22 02:40:43 +0100
committerSlávek Banko <slavek.banko@axis.cz>2022-03-22 02:40:43 +0100
commite919ffc1ec291cc393e48ea0b9b2580a7a4f954a (patch)
treec3de54e8e99924a4c241e742378a6adca10d7584
parentcc9271d7313660307d19677ef53d0ae8e30731fc (diff)
downloadtqt3-e919ffc1ec291cc393e48ea0b9b2580a7a4f954a.tar.gz
tqt3-e919ffc1ec291cc393e48ea0b9b2580a7a4f954a.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 <slavek.banko@axis.cz>
-rw-r--r--src/tools/qstring.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/tools/qstring.cpp b/src/tools/qstring.cpp
index 0c5e52c37..59f8e1423 100644
--- a/src/tools/qstring.cpp
+++ b/src/tools/qstring.cpp
@@ -5999,6 +5999,14 @@ void TQString::setSecurityUnPaged(bool lock) {
*/
TQCString TQString::utf8() const
{
+ if (!d->cString) {
+ d->cString = new TQCString;
+ }
+ if(d == shared_null)
+ {
+ return *d->cString;
+ }
+
int l = length();
int rlen = l*3+1;
TQCString rstr(rlen);
@@ -6043,11 +6051,8 @@ TQCString TQString::utf8() const
++ch;
}
rstr.truncate( cursor - (uchar*)rstr.data() );
- if (!d->cString) {
- d->cString = new TQCString;
- }
*d->cString = rstr;
- return rstr;
+ return *d->cString;
}
static TQChar *addOne(TQChar *qch, TQString &str)
@@ -6251,6 +6256,10 @@ TQCString TQString::local8Bit() const
if (!d->cString) {
d->cString = new TQCString;
}
+ if(d == shared_null)
+ {
+ return *d->cString;
+ }
#ifdef TQT_NO_TEXTCODEC
*d->cString = TQCString(latin1());
return *d->cString;