From 312ff692b02d6b19f39303591c7dc0156bf46661 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 1 Oct 2019 16:36:42 +0200 Subject: Debugger: Do not crash when displaying uninitialized QImages Fixes: QTCREATORBUG-23031 Change-Id: I074cdaf509edac6e5659d2e976ed7188e8944d81 Reviewed-by: Mitch Curtis Reviewed-by: Eike Ziller --- src/plugins/debugger/watchhandler.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 9eccfbdb1e..66d73e84bf 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -2296,15 +2296,20 @@ void WatchModel::showEditValue(const WatchItem *item) QTC_ASSERT(0 < nbytes && nbytes < 10000 * 10000, return); QTC_ASSERT(0 < imformat && imformat < 32, return); QImage im(width, height, QImage::Format(imformat)); - std::memcpy(im.bits(), bits, nbytes); - auto v = m_separatedView->prepareObject(item); - v->setInfo(item->address ? - tr("%1 Object at %2").arg(item->type, item->hexAddress()) : - tr("%1 Object at Unknown Address").arg(item->type) + " " + - ImageViewer::tr("Size: %1x%2, %3 byte, format: %4, depth: %5") - .arg(width).arg(height).arg(nbytes).arg(im.format()).arg(im.depth()) - ); - v->setImage(im); + const qsizetype size = im.sizeInBytes(); + // If our computation of image size doesn't fit the client's + // chances are that we can't properly display it either. + if (size == nbytes) { + std::memcpy(im.bits(), bits, nbytes); + auto v = m_separatedView->prepareObject(item); + v->setInfo(item->address ? + tr("%1 Object at %2").arg(item->type, item->hexAddress()) : + tr("%1 Object at Unknown Address").arg(item->type) + " " + + ImageViewer::tr("Size: %1x%2, %3 byte, format: %4, depth: %5") + .arg(width).arg(height).arg(nbytes).arg(im.format()).arg(im.depth()) + ); + v->setImage(im); + } } else if (format == DisplayLatin1String || format == DisplayUtf8String || format == DisplayUtf16String -- cgit v1.2.1