summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qpicture.cpp
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2017-07-19 16:21:36 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2017-08-16 16:19:52 +0000
commitd7db2b43596b9a51017546eb1c6e2c4e30a0041e (patch)
tree83a1e18535dd02e9fbb52521db0cb137bc51500b /src/gui/image/qpicture.cpp
parentcdc79f5ebc0ec1898e3845acb9c880b5e69e593b (diff)
QPicture: check that pictureFormat doesn't return dangling pointers
The function returns a const char * out of a QByteArray. We must be sure that the QByteArray outlives the function, otherwise the pointer returned would be dangling. Add an assertion for that. Found by clazy. Change-Id: I3416af4eb5ec79ddb3e4baf3bdcfe046b44d4225 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/gui/image/qpicture.cpp')
-rw-r--r--src/gui/image/qpicture.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp
index 7506e2e1a9..010f5ecf67 100644
--- a/src/gui/image/qpicture.cpp
+++ b/src/gui/image/qpicture.cpp
@@ -1206,7 +1206,12 @@ QT_END_INCLUDE_NAMESPACE
const char* QPicture::pictureFormat(const QString &fileName)
{
- return QPictureIO::pictureFormat(fileName);
+ const QByteArray format = QPictureIO::pictureFormat(fileName);
+ // This function returns a const char * from a QByteArray.
+ // Double check that the QByteArray is not detached, otherwise
+ // we would return a dangling pointer.
+ Q_ASSERT(!format.isDetached());
+ return format;
}
/*!