summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-07-10 12:52:57 +0200
committerMarc Mutz <[email protected]>2025-07-14 22:25:35 +0000
commitb9f6a1b113d8f26210da5c3194f0f790883761fe (patch)
tree9d081c5ce065e8a43d37b1396e96f62a346fb294
parent8e398cec88f6019edc83e52cab64e3ef52bef173 (diff)
QTextStream: use write(QChar) more
Replace write(&ch, 1) calls with write(ch) ones. The QChar overload, added in 31c6d9f04ba80e6776ae01cb0588e6bd228f7184, is safer, because it has less preconditions. With QTextStream being security-critical, we should target to use safer functions to do the same work, even if it introduces a bit of git history churn. The call from a different TU (qdebug.cpp) means we need to remove the lying inline keywords from both declaration and definition of write(QChar), because GCC -Werrors on them. As a drive-by, remove a use of QLatin1Char, in preparation of moving from QChar to char16_t, eventually. Pick-to: 6.10 6.9 6.8 Change-Id: I97b4c8c68a4ee0d4b821c4d2ec4a9dd6f44dceb0 Reviewed-by: Thiago Macieira <[email protected]>
-rw-r--r--src/corelib/io/qdebug.cpp7
-rw-r--r--src/corelib/serialization/qtextstream.cpp6
-rw-r--r--src/corelib/serialization/qtextstream_p.h2
3 files changed, 7 insertions, 8 deletions
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp
index 70a688e40ff..5d6b5e06be6 100644
--- a/src/corelib/io/qdebug.cpp
+++ b/src/corelib/io/qdebug.cpp
@@ -200,7 +200,7 @@ template <typename Char>
static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, size_t length, bool isUnicode = true)
{
QChar quote(u'"');
- d->write(&quote, 1);
+ d->write(quote);
bool lastWasHexEscape = false;
const Char *end = begin + length;
@@ -227,8 +227,7 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, si
continue;
}
} else if (isPrintable(*p) && *p != '\\' && *p != '"') {
- QChar c = QLatin1Char(*p);
- d->write(&c, 1);
+ d->write(char16_t{uchar(*p)});
continue;
}
@@ -302,7 +301,7 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, si
d->write(reinterpret_cast<QChar *>(buf), buflen);
}
- d->write(&quote, 1);
+ d->write(quote);
}
/*!
diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp
index 5e0eff698f9..e4dc98af98b 100644
--- a/src/corelib/serialization/qtextstream.cpp
+++ b/src/corelib/serialization/qtextstream.cpp
@@ -711,7 +711,7 @@ void QTextStreamPrivate::write(const QChar *data, qsizetype len)
/*!
\internal
*/
-inline void QTextStreamPrivate::write(QChar ch)
+void QTextStreamPrivate::write(QChar ch)
{
if (string) {
// ### What about seek()??
@@ -845,7 +845,7 @@ void QTextStreamPrivate::putString(const QChar *data, qsizetype len, bool number
const QChar sign = len > 0 ? data[0] : QChar();
if (sign == locale.negativeSign() || sign == locale.positiveSign()) {
// write the sign before the padding, then skip it later
- write(&sign, 1);
+ write(sign);
++data;
--len;
}
@@ -874,7 +874,7 @@ void QTextStreamPrivate::putString(QLatin1StringView data, bool number)
const QChar sign = data.size() > 0 ? QLatin1Char(*data.data()) : QChar();
if (sign == locale.negativeSign() || sign == locale.positiveSign()) {
// write the sign before the padding, then skip it later
- write(&sign, 1);
+ write(sign);
data = QLatin1StringView(data.data() + 1, data.size() - 1);
}
}
diff --git a/src/corelib/serialization/qtextstream_p.h b/src/corelib/serialization/qtextstream_p.h
index 7227c29c8fe..bf3ce7b2ef7 100644
--- a/src/corelib/serialization/qtextstream_p.h
+++ b/src/corelib/serialization/qtextstream_p.h
@@ -145,7 +145,7 @@ public:
bool getReal(double *f);
inline void write(QStringView data) { write(data.begin(), data.size()); }
- inline void write(QChar ch);
+ void write(QChar ch);
void write(const QChar *data, qsizetype len);
void write(QLatin1StringView data);
void writePadding(qsizetype len);