diff options
| author | Ahmad Samir <a.samirh78@gmail.com> | 2025-06-16 12:57:42 +0300 |
|---|---|---|
| committer | Ahmad Samir <a.samirh78@gmail.com> | 2025-06-17 03:25:15 +0300 |
| commit | 96f4010d2c669ea43d1288f2e8d713ab2a56ef06 (patch) | |
| tree | d15f192d5e814afde921a313d72c229a2e0adcd2 /src/corelib/text/qstring.cpp | |
| parent | b29531aa954f8f099a5f8340d1b5b102cf36bfd7 (diff) | |
QString/QByteArray: de-inline nullTerminate*()
From the API review:
«QBA is security-critical, so we shouldn't have too much stuff in the
header; and certainly not if it involves manipulation of the atomics»
Pick-to: 6.10
Change-Id: I314c6b09b6445901e92958b3db0fa51efd808eba
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/text/qstring.cpp')
| -rw-r--r-- | src/corelib/text/qstring.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index b2f4919c7c4..abba4b12fb2 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -7077,9 +7077,17 @@ const ushort *QString::utf16() const \sa nullTerminated(), fromRawData(), setRawData() */ +QString &QString::nullTerminate() +{ + // ensure '\0'-termination for ::fromRawData strings + if (!d->isMutable()) + *this = QString{constData(), size()}; + return *this; +} /*! \fn QString QString::nullTerminated() const & + \fn QString QString::nullTerminated() && \since 6.10 Returns a copy of this string that is always null-terminated. @@ -7087,6 +7095,19 @@ const ushort *QString::utf16() const \sa nullTerminated(), fromRawData(), setRawData() */ +QString QString::nullTerminated() const & +{ + // ensure '\0'-termination for ::fromRawData strings + if (!d->isMutable()) + return QString{constData(), size()}; + return *this; +} + +QString QString::nullTerminated() && +{ + nullTerminate(); + return std::move(*this); +} /*! Returns a string of size \a width that contains this string |
