Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-3967

On Unix, with the GNU libraries, qt_error_string() return empty string for some errors

    XMLWordPrintable

Details

    • 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
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            poulain Benjamin Poulain (closed Nokia identity) (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes