summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2010-01-21 10:28:00 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2010-01-21 11:48:09 (GMT)
commit694be5a31be7e24761753ab9eccd87e8d08607e0 (patch)
treeacc4fcf9eba015cbbdd202775bd2230cf8af8e5f
parent967b6980372b3a3b988d2284bdd10b8154482680 (diff)
downloadQt-694be5a31be7e24761753ab9eccd87e8d08607e0.zip
Qt-694be5a31be7e24761753ab9eccd87e8d08607e0.tar.gz
Qt-694be5a31be7e24761753ab9eccd87e8d08607e0.tar.bz2
qUncompress: Fix terminating \0
Task-number: 6666 Reviewed-by: Harald Fernengel <harald.fernengel@nokia.com>
-rw-r--r--src/corelib/tools/qbytearray.cpp1
-rw-r--r--tests/auto/qbytearray/tst_qbytearray.cpp9
2 files changed, 10 insertions, 0 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 4049925..556093f 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -561,6 +561,7 @@ QByteArray qUncompress(const uchar* data, int nbytes)
d->ref = 1;
d->alloc = d->size = len;
d->data = d->array;
+ d->array[len] = 0;
return QByteArray(d.take(), 0, 0);
diff --git a/tests/auto/qbytearray/tst_qbytearray.cpp b/tests/auto/qbytearray/tst_qbytearray.cpp
index 35e4463..5c72c7a 100644
--- a/tests/auto/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/qbytearray/tst_qbytearray.cpp
@@ -76,6 +76,7 @@ private slots:
void qCompress();
void qUncompress_data();
void qUncompress();
+ void qCompressionZeroTermination();
#endif
void constByteArray();
void leftJustified();
@@ -261,6 +262,14 @@ void tst_QByteArray::qUncompress()
}
QCOMPARE(res, out);
}
+
+void tst_QByteArray::qCompressionZeroTermination()
+{
+ QString s = "Hello, I'm a string.";
+ QByteArray ba = ::qUncompress(::qCompress(s.toLocal8Bit()));
+ QVERIFY((int) *(ba.data() + ba.size()) == 0);
+}
+
#endif
void tst_QByteArray::constByteArray()