Debugger: Do not crash when displaying uninitialized QImages

Fixes: QTCREATORBUG-23031
Change-Id: I074cdaf509edac6e5659d2e976ed7188e8944d81
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2019-10-01 16:36:42 +02:00
parent 0907bc8658
commit 312ff692b0

View File

@@ -2296,15 +2296,20 @@ void WatchModel::showEditValue(const WatchItem *item)
QTC_ASSERT(0 < nbytes && nbytes < 10000 * 10000, return); QTC_ASSERT(0 < nbytes && nbytes < 10000 * 10000, return);
QTC_ASSERT(0 < imformat && imformat < 32, return); QTC_ASSERT(0 < imformat && imformat < 32, return);
QImage im(width, height, QImage::Format(imformat)); QImage im(width, height, QImage::Format(imformat));
std::memcpy(im.bits(), bits, nbytes); const qsizetype size = im.sizeInBytes();
auto v = m_separatedView->prepareObject<ImageViewer>(item); // If our computation of image size doesn't fit the client's
v->setInfo(item->address ? // chances are that we can't properly display it either.
tr("%1 Object at %2").arg(item->type, item->hexAddress()) : if (size == nbytes) {
tr("%1 Object at Unknown Address").arg(item->type) + " " + std::memcpy(im.bits(), bits, nbytes);
ImageViewer::tr("Size: %1x%2, %3 byte, format: %4, depth: %5") auto v = m_separatedView->prepareObject<ImageViewer>(item);
.arg(width).arg(height).arg(nbytes).arg(im.format()).arg(im.depth()) v->setInfo(item->address ?
); tr("%1 Object at %2").arg(item->type, item->hexAddress()) :
v->setImage(im); 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 } else if (format == DisplayLatin1String
|| format == DisplayUtf8String || format == DisplayUtf8String
|| format == DisplayUtf16String || format == DisplayUtf16String