diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-07-27 11:06:59 +0300 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2019-07-29 12:45:08 +0000 |
commit | 93b845464fa7ac29c26e1835fd3a6cfac33d9a9d (patch) | |
tree | a6218a8cc69159c75e654d989dab2ef1c58ac08b /src/corelib/text/qstringview.h | |
parent | adab531771a1ddce7df6652449b7977f340ebfc7 (diff) |
QStringView: two fixes for newly-added toWCharArray()
Amends e89fbd8c3aa50a24e5fc02ab710ccca67fce98e2.
- While QString::data() never returns nullptr, QStringView::data()
may, which makes calling QStringView{}.toWCharArray() UB on Windows
(since memcpy's 2nd argument must never be nullptr, even if the size
is zero). Fix by protecting the memcpy call.
- QStringView, by design, does not use out-of-line member functions,
because calling these forces the QStringView object onto the stack.
Fix by making inline.
Also use the more efficient qToStringViewIgnoringNull(), as the result
does not depend on QString::isNull() (no characters are written
either way), and add a missing article to the function's docs.
Change-Id: I5d6b31361522812b0db8303b93c43d4b9ed11933
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/text/qstringview.h')
-rw-r--r-- | src/corelib/text/qstringview.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index b84b2995b9..5a3acaa8c0 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -294,7 +294,7 @@ public: Q_REQUIRED_RESULT bool isRightToLeft() const noexcept { return QtPrivate::isRightToLeft(*this); } - Q_REQUIRED_RESULT Q_CORE_EXPORT int toWCharArray(wchar_t *array) const; + Q_REQUIRED_RESULT inline int toWCharArray(wchar_t *array) const; // defined in qstring.h // // STL compatibility API: |