diff options
-rw-r--r-- | src/gui/image/qpixmap.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qpixmap/tst_qpixmap.cpp | 21 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index a3b7516..45ff5f4 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -860,6 +860,9 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags) { + if (len == 0 || buf == 0) + return false; + return data->fromData(buf, len, format, flags); } diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index 9f5aee2..53b6230 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -166,6 +166,7 @@ private slots: void fromImage_crash(); void fromData(); + void loadFromDataNullValues(); void preserveDepth(); }; @@ -1436,6 +1437,26 @@ void tst_QPixmap::fromData() QCOMPARE(img.pixel(0, 1), QRgb(0xff000000)); } +void tst_QPixmap::loadFromDataNullValues() +{ + { + QPixmap pixmap; + pixmap.loadFromData(QByteArray()); + QVERIFY(pixmap.isNull()); + } + { + QPixmap pixmap; + pixmap.loadFromData(0, 123); + QVERIFY(pixmap.isNull()); + } + { + QPixmap pixmap; + const uchar bla[] = "bla"; + pixmap.loadFromData(bla, 0); + QVERIFY(pixmap.isNull()); + } +} + void tst_QPixmap::task_246446() { // This crashed without the bugfix in 246446 |