summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Köhne <kai.koehne@qt.io>2021-03-05 10:35:04 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-10 16:34:10 +0000
commita4a4c76f2bf83e173978f3f4bfcaeec07d7d503d (patch)
tree804d8b3015801bfe58f060089efc175c08e710f0
parentbf19b61b4508d606218b351f7e0628b2d6b489dd (diff)
downloadqttools-a4a4c76f2bf83e173978f3f4bfcaeec07d7d503d.tar.gz
Fix regression in lconvert handling empty translations
Fixes a regression introduced by commit b96fe95da00aca6b, which enabled a sanity check that now failed to account for empty string. The serialized format of a QString is such that '-1' indicates a null string, otherwise it's <length><QChar>+. Since QChar is 2 bytes, length should therefore always be an even number ... except for -1. While at it, also preserve the difference between an empty string and a null string. Fixes: QTBUG-91558 Change-Id: Iffbc6ee2c94b8363d2c1d91440022a77dbef4772 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit b9a9f7b502f0631144176be343779a698e54161e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/linguist/shared/qm.cpp11
-rw-r--r--tests/auto/linguist/lconvert/data/untranslated.qmbin0 -> 222 bytes
-rw-r--r--tests/auto/linguist/lconvert/tst_lconvert.cpp2
3 files changed, 10 insertions, 3 deletions
diff --git a/src/linguist/shared/qm.cpp b/src/linguist/shared/qm.cpp
index 6036d6075..c94ca7b82 100644
--- a/src/linguist/shared/qm.cpp
+++ b/src/linguist/shared/qm.cpp
@@ -546,12 +546,17 @@ bool loadQM(Translator &translator, QIODevice &dev, ConversionData &cd)
goto end;
case Tag_Translation: {
int len = read32(m);
- if (len & 1) {
+ m += 4;
+
+ // -1 indicates an empty string
+ // Otherwise streaming format is UTF-16 -> 2 bytes per character
+ if ((len != -1) && (len & 1)) {
cd.appendError(QLatin1String("QM-Format error"));
return false;
}
- m += 4;
- QString str = QString((const QChar *)m, len/2);
+ QString str;
+ if (len != -1)
+ str = QString((const QChar *)m, len / 2);
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
for (int i = 0; i < str.length(); ++i)
str[i] = QChar((str.at(i).unicode() >> 8) +
diff --git a/tests/auto/linguist/lconvert/data/untranslated.qm b/tests/auto/linguist/lconvert/data/untranslated.qm
new file mode 100644
index 000000000..e31d2553a
--- /dev/null
+++ b/tests/auto/linguist/lconvert/data/untranslated.qm
Binary files differ
diff --git a/tests/auto/linguist/lconvert/tst_lconvert.cpp b/tests/auto/linguist/lconvert/tst_lconvert.cpp
index 14f97a97a..2d3a1f5d2 100644
--- a/tests/auto/linguist/lconvert/tst_lconvert.cpp
+++ b/tests/auto/linguist/lconvert/tst_lconvert.cpp
@@ -282,6 +282,7 @@ void tst_lconvert::roundtrips_data()
QStringList tsPoTs; tsPoTs << "ts" << "po" << "ts";
QStringList tsXlfTs; tsXlfTs << "ts" << "xlf" << "ts";
QStringList tsQmTs; tsQmTs << "ts" << "qm" << "ts";
+ QStringList qmTsQm; qmTsQm << "qm" << "ts" << "qm";
QList<QStringList> noArgs;
QList<QStringList> filterPoArgs; filterPoArgs << QStringList() << (QStringList() << "-drop-tag" << "po:*");
@@ -318,6 +319,7 @@ void tst_lconvert::roundtrips_data()
QTest::newRow("ts-po-ts (endless loop)") << "endless-po-loop.ts" << tsPoTs << noArgs;
QTest::newRow("ts-qm-ts (whitespace)") << "whitespace.ts" << tsQmTs << noArgs;
+ QTest::newRow("qm-ts-qm (untranslated)") << "untranslated.qm" << qmTsQm << noArgs;
}
void tst_lconvert::roundtrips()