From 8383c2ff7f383385707bd2fc3e33071988507910 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 31 Oct 2018 12:51:15 +0100 Subject: QIODevice bindings: Fix invalid reads in read() functions When running test in debug mode on Windows, failures occurred: File "sources/pyside2/tests/QtCore/qfileread_test.py", line 41, in readData return super(FileChild2, self).readData(maxlen) UnicodeDecodeError 'utf-8' codec can't decode byte 0xcd in position 21: invalid continuation byte File "C:/dev/pyside/pyside-setup511d/sources/pyside2/tests/QtCore/qfile_test.py", line 57, in testBasic self.assertFalse(obj.getChar()[0]) UnicodeDecodeError 'utf-8' codec can't decode byte 0xcc in position 0: unexpected end of data This is caused by missing initializers and terminating \0 characters in the QByteArrays introduced by ca806b438e8a27dc4562ac806d189765e93e09e5, unearthed by MSVC helpfully filling unitinialized data with random values. Fix by using a QByteArray of size n + 1 filled with 0. Initialize the character variable in the fix_char* template. Task-number: PYSIDE-40 Change-Id: Ia604841a89f1b1b9564c16d2f23cd9f7c20f5628 Reviewed-by: Alexandru Croitor --- sources/pyside2/PySide2/QtCore/typesystem_core_common.xml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'sources/pyside2/PySide2/QtCore') diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index 631403c3f..48f234f2b 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -3035,9 +3035,8 @@ - QByteArray ba; - ba.resize(%2); - %CPPSELF.%FUNCTION_NAME(ba.data(), ba.size()); + QByteArray ba(1 + int(%2), char(0)); + %CPPSELF.%FUNCTION_NAME(ba.data(), int(%2)); %PYARG_0 = Shiboken::String::fromCString(ba.constData()); @@ -3059,9 +3058,8 @@ - QByteArray ba; - ba.resize(%2); - %CPPSELF.%FUNCTION_NAME(ba.data(), ba.size()); + QByteArray ba(1 + int(%2), char(0)); + %CPPSELF.%FUNCTION_NAME(ba.data(), int(%2)); %PYARG_0 = Shiboken::String::fromCString(ba.constData()); -- cgit v1.2.3