summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-01-25 19:59:51 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-01-26 14:08:07 +0000
commit088eef57566cb59b9c3b10e218a80b0516cb7e8a (patch)
tree9d89985a0497f79c48dbad726d5b968055739cc0 /src/corelib
parent5dbf8756efc40b087beca368c6612d404c2d13b1 (diff)
QStringBuilder: fix appending QLatin1String to QByteArray
The old code did the equivalent of strcpy(), thus stopping at the first NUL byte, ignoring the QLatin1String's size(). That is not acceptable, for two reasons: 1. Appending QLatin1String to a QString uses the size(), too. 2. The QConcatenable claims an ExactSize = true, so it cannot go and write less data than it's own size() said it would. Even worse, it will happily write _more_ data, too, if the QLatin1String is not properly zero-terminated. This change has low risk, because the equivalent change to the QString branch has been applied between 5.2 and 5.3 (in fd0f1bc3), with no complaints from the user base. It is also in a branch that is very unlikely to be taken: Since QConcatenable<QLatin1String> is setting ConvertTo to QString, any QStringBuilder expression containing it will only implicitly convert to QString, not QByteArray. In fact, I don't even know how to make it invoke the changed code in normal operation... Change-Id: I486a76352af7f318ba05da845d3afee7d826c92a Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qstringbuilder.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h
index 3d41aeee18..69bd344f47 100644
--- a/src/corelib/tools/qstringbuilder.h
+++ b/src/corelib/tools/qstringbuilder.h
@@ -236,9 +236,9 @@ template <> struct QConcatenable<QLatin1String> : private QAbstractConcatenable
}
static inline void appendTo(const QLatin1String a, char *&out)
{
- if (a.data()) {
- for (const char *s = a.data(); *s; )
- *out++ = *s++;
+ if (const char *data = a.data()) {
+ memcpy(out, data, a.size());
+ out += a.size();
}
}
};