From e177a35dfe62dfebdd1381f30dc5f5b83b1d6b74 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 22 Aug 2012 13:51:45 +0200 Subject: [PATCH] ICU: Fix crash in codecForMib(2107) availableMibs() unconditionally adds 2107 to the list of mibs. The patch ensures that codecForMib() also knows about this special TSCII codec. (Note that the autotest only really checks this code path if only this test case is run. The other tests already fill the internal codec cache otherwise). Change-Id: Id987d7cecd5f5700cca75e9b85b37011f8e5c622 Reviewed-by: Lars Knoll --- src/corelib/codecs/qicucodec.cpp | 4 ++++ tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/corelib/codecs/qicucodec.cpp b/src/corelib/codecs/qicucodec.cpp index b591a3d50d..e348e68753 100644 --- a/src/corelib/codecs/qicucodec.cpp +++ b/src/corelib/codecs/qicucodec.cpp @@ -530,6 +530,10 @@ QTextCodec *QIcuCodec::codecForMibUnlocked(int mib) if (mibToName[i].mib == mib) return codecForNameUnlocked(mibToNameTable + mibToName[i].index); } + + if (mib == 2107) + return codecForNameUnlocked("TSCII"); + return 0; } diff --git a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp index 2eac72db29..c32c6f9573 100644 --- a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp +++ b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp @@ -73,6 +73,7 @@ private slots: void decode0D() const; void aliasForUTF16() const; void mibForTSCII() const; + void codecForTSCII() const; void utf8Codec_data(); void utf8Codec(); @@ -513,6 +514,13 @@ void tst_QTextCodec::mibForTSCII() const QCOMPARE(codec->mibEnum(), 2107); } +void tst_QTextCodec::codecForTSCII() const +{ + QTextCodec *codec = QTextCodec::codecForMib(2107); + QVERIFY(codec); + QCOMPARE(codec->mibEnum(), 2107); +} + static QString fromInvalidUtf8Sequence(const QByteArray &ba) { return QString().fill(QChar::ReplacementCharacter, ba.size());