diff options
Diffstat (limited to 'src/corelib/global/qglobal.cpp')
-rw-r--r-- | src/corelib/global/qglobal.cpp | 57 |
1 files changed, 20 insertions, 37 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index d2805f52e1..e9a75ba9e8 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -2283,19 +2283,19 @@ static bool readEtcFile(QUnixOSVersion &v, const char *filename, line.setRawData(ptr, eol - ptr); if (line.startsWith(idKey)) { - ptr += idKey.length(); + ptr += idKey.size(); v.productType = unquote(ptr, eol); continue; } if (line.startsWith(prettyNameKey)) { - ptr += prettyNameKey.length(); + ptr += prettyNameKey.size(); v.prettyName = unquote(ptr, eol); continue; } if (line.startsWith(versionKey)) { - ptr += versionKey.length(); + ptr += versionKey.size(); v.productVersion = unquote(ptr, eol); continue; } @@ -2332,7 +2332,7 @@ static bool readEtcLsbRelease(QUnixOSVersion &v) int fd = qt_safe_open(distrorelease, O_RDONLY); if (fd != -1) { QT_STATBUF sbuf; - if (QT_FSTAT(fd, &sbuf) != -1 && sbuf.st_size > v.prettyName.length()) { + if (QT_FSTAT(fd, &sbuf) != -1 && sbuf.st_size > v.prettyName.size()) { // file apparently contains interesting information QByteArray buffer(sbuf.st_size, Qt::Uninitialized); buffer.resize(qt_safe_read(fd, buffer.data(), sbuf.st_size)); @@ -3619,6 +3619,14 @@ bool qEnvironmentVariableIsSet(const char *varName) noexcept */ bool qputenv(const char *varName, const QByteArray &value) { + // protect against non-NUL-terminated QByteArrays: + if (!const_cast<QByteArray&>(value).data_ptr()->isMutable()) { + QByteArray copy(value); + copy.reserve(copy.size() + 1); // ensures NUL termination (and isMutable() even for size==0 + // (unlike detach()) to avoid infinite recursion) + return qputenv(varName, copy); + } + #if defined(Q_CC_MSVC) const auto locker = qt_scoped_lock(environmentMutex); return _putenv_s(varName, value.constData()) == 0; @@ -3803,8 +3811,9 @@ bool qunsetenv(const char *varName) Replaces the value of \a obj with \a newValue and returns the old value of \a obj. This is Qt's implementation of std::exchange(). It differs from std::exchange() - only in that it is \c constexpr already in C++14, and available on all supported - compilers. + only in that it is \c constexpr already before C++20 and noexcept already before C++23. + + We strongly advise to use std::exchange() when you don't need the C++20 or C++23 variants. Here is how to use qExchange() to implement move constructors: \code @@ -4571,26 +4580,22 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) /*! \macro Q_DECL_CONSTEXPR \relates <QtGlobal> + \deprecated [6.4] Use the \c constexpr keyword instead. This macro can be used to declare variable that should be constructed at compile-time, or an inline function that can be computed at compile-time. - It expands to "constexpr" if your compiler supports that C++11 keyword, or to nothing - otherwise. - \sa Q_DECL_RELAXED_CONSTEXPR */ /*! \macro Q_DECL_RELAXED_CONSTEXPR \relates <QtGlobal> + \deprecated [6.4] Use the \c constexpr keyword instead. This macro can be used to declare an inline function that can be computed at compile-time according to the relaxed rules from C++14. - It expands to "constexpr" if your compiler supports C++14 relaxed constant - expressions, or to nothing otherwise. - \sa Q_DECL_CONSTEXPR */ @@ -4784,18 +4789,12 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) \macro Q_DECL_NOTHROW \relates <QtGlobal> \since 5.0 + \deprecated [6.4] Use the \c noexcept keyword instead. This macro marks a function as never throwing, under no circumstances. If the function does nevertheless throw, the behaviour is undefined. - The macro expands to either "throw()", if that has some benefit on - the compiler, or to C++11 noexcept, if available, or to nothing - otherwise. - - If you need C++11 noexcept semantics, don't use this macro, use - Q_DECL_NOEXCEPT/Q_DECL_NOEXCEPT_EXPR instead. - \sa Q_DECL_NOEXCEPT, Q_DECL_NOEXCEPT_EXPR() */ @@ -4833,20 +4832,12 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) \macro Q_DECL_NOEXCEPT \relates <QtGlobal> \since 5.0 + \deprecated [6.4] Use the \c noexcept keyword instead. This macro marks a function as never throwing. If the function does nevertheless throw, the behaviour is defined: std::terminate() is called. - The macro expands to C++11 noexcept, if available, or to nothing - otherwise. - - If you need the operator version of C++11 noexcept, use - Q_DECL_NOEXCEPT_EXPR(x). - - If you don't need C++11 noexcept semantics, e.g. because your - function can't possibly throw, don't use this macro, use - Q_DECL_NOTHROW instead. \sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT_EXPR() */ @@ -4855,20 +4846,12 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) \macro Q_DECL_NOEXCEPT_EXPR(x) \relates <QtGlobal> \since 5.0 + \deprecated [6.4] Use the \c noexcept keyword instead. This macro marks a function as non-throwing if \a x is \c true. If the function does nevertheless throw, the behaviour is defined: std::terminate() is called. - The macro expands to C++11 noexcept(x), if available, or to - nothing otherwise. - - If you need the always-true version of C++11 noexcept, use - Q_DECL_NOEXCEPT. - - If you don't need C++11 noexcept semantics, e.g. because your - function can't possibly throw, don't use this macro, use - Q_DECL_NOTHROW instead. \sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT */ |