Fix crash in QStringBuilder when concatenating data-less QLatin1String

Previously, the append functions in QConcatenable in the QStringBuilder
dereferenced the data() pointer of the argument QLatin1String without
performing null check.

Change-Id: I629f19fbce3113f1f80f4272fa7ae34e1dbc6bee
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Chris Adams 2012-05-31 14:00:48 +10:00 committed by Qt by Nokia
parent 1e778ebd06
commit fbee9834dc
2 changed files with 15 additions and 4 deletions

View File

@ -230,13 +230,17 @@ template <> struct QConcatenable<QLatin1String>
static int size(const QLatin1String a) { return a.size(); }
static inline void appendTo(const QLatin1String a, QChar *&out)
{
for (const char *s = a.data(); *s; )
*out++ = QLatin1Char(*s++);
if (a.data()) {
for (const char *s = a.data(); *s; )
*out++ = QLatin1Char(*s++);
}
}
static inline void appendTo(const QLatin1String a, char *&out)
{
for (const char *s = a.data(); *s; )
*out++ = *s++;
if (a.data()) {
for (const char *s = a.data(); *s; )
*out++ = *s++;
}
}
};

View File

@ -211,6 +211,13 @@ void runScenario()
str = (QString::fromUtf8(UTF8_LITERAL) += QLatin1String(LITERAL) P UTF8_LITERAL);
QCOMPARE(str, QString::fromUtf8(UTF8_LITERAL LITERAL UTF8_LITERAL));
#endif
QString str2 = QString::fromUtf8(UTF8_LITERAL);
QString str2_e = QString::fromUtf8(UTF8_LITERAL);
const char * nullData = 0;
str2 += QLatin1String(nullData) P str2;
str2_e += QLatin1String("") P str2_e;
QCOMPARE(str2, str2_e);
}
//operator QByteArray +=