Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
4.5.0
-
None
-
e3894396b663ff674c4af19b87b34bdf688c19b2
Description
qt_error_string() uses strerror_r() to get the message corresponding to the error code. This function is available in two versions: a GNU version and a POSIX version (see http://linuxcertif.com/man/3/strerror_r/en/).
The GNU version does not always use the buffer to return the error, for some error the pointer returned is the error string.
Here is a patch by Andy Goth for the issue:
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index c85ae84..f35e33a 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1898,10 +1898,13 @@ QString qt_error_string(int errorCode) ret = QString::fromLatin1("The specified module could not be found."); #elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY) - QByteArray buf(1024, '\0'); - strerror_r(errorCode, buf.data(), buf.size()); - ret = QString::fromLocal8Bit(buf.constData()); + #if defined(_GNU_SOURCE) + ret = QString::fromLocal8Bit(strerror_r(errorCode, buf.data(), buf.size())); + #else + strerror_r(errorCode, buf.data(), buf.size()); + ret = QString::fromLocal8Bit(buf.constData()); + #endif #else ret = QString::fromLocal8Bit(strerror(errorCode)); #endif