diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-04-26 09:15:08 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-04-26 09:15:08 (GMT) |
commit | a8a00b61c5a614f0bcf59527327c0ebe13ab3904 (patch) | |
tree | d2ac65fa5b0bc30de3a7812ed27819466703373e /src/corelib | |
parent | 804971eae867f1abe4a769abfecf3221ba65c85a (diff) | |
parent | 674755d19160f8724df8fa8e19daeafc653ae543 (diff) | |
download | Qt-a8a00b61c5a614f0bcf59527327c0ebe13ab3904.zip Qt-a8a00b61c5a614f0bcf59527327c0ebe13ab3904.tar.gz Qt-a8a00b61c5a614f0bcf59527327c0ebe13ab3904.tar.bz2 |
Merge branch '4.6' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.6-integration
* '4.6' of scm.dev.nokia.troll.no:qt/oslo-staging-1:
Fix infinite recursion in QIconvCodec when iconv fails.
Fix the use of strerror_r on GNU libc systems.
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/codecs/qiconvcodec.cpp | 22 | ||||
-rw-r--r-- | src/corelib/global/qglobal.cpp | 28 |
2 files changed, 34 insertions, 16 deletions
diff --git a/src/corelib/codecs/qiconvcodec.cpp b/src/corelib/codecs/qiconvcodec.cpp index 0fcdf96..44a0a01 100644 --- a/src/corelib/codecs/qiconvcodec.cpp +++ b/src/corelib/codecs/qiconvcodec.cpp @@ -168,7 +168,7 @@ Q_GLOBAL_STATIC(QThreadStorage<QIconvCodec::IconvState *>, toUnicodeState) QString QIconvCodec::convertToUnicode(const char* chars, int len, ConverterState *convState) const { if (utf16Codec == reinterpret_cast<QTextCodec *>(~0)) - return QString::fromAscii(chars, len); + return QString::fromLatin1(chars, len); int invalidCount = 0; int remainingCount = 0; @@ -207,9 +207,9 @@ QString QIconvCodec::convertToUnicode(const char* chars, int len, ConverterState static int reported = 0; if (!reported++) { fprintf(stderr, - "QIconvCodec::convertToUnicode: using ASCII for conversion, iconv_open failed\n"); + "QIconvCodec::convertToUnicode: using Latin-1 for conversion, iconv_open failed\n"); } - return QString::fromAscii(chars, len); + return QString::fromLatin1(chars, len); } *pstate = new IconvState(cd); @@ -273,14 +273,14 @@ QString QIconvCodec::convertToUnicode(const char* chars, int len, ConverterState // some other error // note, cannot use qWarning() since we are implementing the codecForLocale :) - perror("QIconvCodec::convertToUnicode: using ASCII for conversion, iconv failed"); + perror("QIconvCodec::convertToUnicode: using Latin-1 for conversion, iconv failed"); if (!convState) { // reset state iconv(state->cd, 0, &inBytesLeft, 0, &outBytesLeft); } - return QString::fromAscii(chars, len); + return QString::fromLatin1(chars, len); } } while (inBytesLeft != 0); @@ -353,12 +353,12 @@ QByteArray QIconvCodec::convertFromUnicode(const QChar *uc, int len, ConverterSt state = new IconvState(QIconvCodec::createIconv_t(0, UTF16)); if (state->cd == reinterpret_cast<iconv_t>(-1)) { if (!setByteOrder(state->cd)) { - perror("QIconvCodec::convertFromUnicode: using ASCII for conversion, iconv failed for BOM"); + perror("QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv failed for BOM"); iconv_close(state->cd); state->cd = reinterpret_cast<iconv_t>(-1); - return QString(uc, len).toAscii(); + return QString(uc, len).toLatin1(); } } } @@ -366,9 +366,9 @@ QByteArray QIconvCodec::convertFromUnicode(const QChar *uc, int len, ConverterSt static int reported = 0; if (!reported++) { fprintf(stderr, - "QIconvCodec::convertFromUnicode: using ASCII for conversion, iconv_open failed\n"); + "QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv_open failed\n"); } - return QString(uc, len).toAscii(); + return QString(uc, len).toLatin1(); } size_t outBytesLeft = len; @@ -425,12 +425,12 @@ QByteArray QIconvCodec::convertFromUnicode(const QChar *uc, int len, ConverterSt default: { // note, cannot use qWarning() since we are implementing the codecForLocale :) - perror("QIconvCodec::convertFromUnicode: using ASCII for conversion, iconv failed"); + perror("QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv failed"); // reset to initial state iconv(state->cd, 0, &inBytesLeft, 0, &outBytesLeft); - return QString(uc, len).toAscii(); + return QString(uc, len).toLatin1(); } } } diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index c8f836a..66519be 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -2074,7 +2074,28 @@ static void mac_default_handler(const char *msg) } #endif // Q_CC_MWERKS && Q_OS_MACX - +#if !defined(Q_OS_WIN) && !defined(QT_NO_THREAD) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) && \ + defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L +namespace { + // There are two incompatible versions of strerror_r: + // a) the XSI/POSIX.1 version, which returns an int, + // indicating success or not + // b) the GNU version, which returns a char*, which may or may not + // be the beginning of the buffer we used + // The GNU libc manpage for strerror_r says you should use the the XSI + // version in portable code. However, it's impossible to do that if + // _GNU_SOURCE is defined so we use C++ overloading to decide what to do + // depending on the return type + static inline QString fromstrerror_helper(int, const QByteArray &buf) + { + return QString::fromLocal8Bit(buf); + } + static inline QString fromstrerror_helper(const char *str, const QByteArray &) + { + return QString::fromLocal8Bit(str); + } +} +#endif QString qt_error_string(int errorCode) { @@ -2117,12 +2138,9 @@ QString qt_error_string(int errorCode) if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND) 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) && !defined(Q_OS_QNX) - QByteArray buf(1024, '\0'); - strerror_r(errorCode, buf.data(), buf.size()); - ret = QString::fromLocal8Bit(buf.constData()); + ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf); #else ret = QString::fromLocal8Bit(strerror(errorCode)); #endif |