BinEditor: Fix crash on editor initialization

MemoryAgent::doCreateBinEditor calls openEditorWithContents, with empty
contents.

The BinEditor fails to handle this case, and crashes when it divides by
zero.

Task-number: QTCREATORBUG-15835
Change-Id: I8009ef991a445ef4cc192d1bda6a208d51e2b48b
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2016-03-08 16:54:12 +02:00
committed by Orgad Shaneh
parent 83e3d954f9
commit 9057143228
2 changed files with 5 additions and 2 deletions

View File

@@ -376,6 +376,7 @@ bool BinEditorWidget::save(QString *errorString, const QString &oldFileName, con
void BinEditorWidget::setSizes(quint64 startAddr, int range, int blockSize) void BinEditorWidget::setSizes(quint64 startAddr, int range, int blockSize)
{ {
int newBlockSize = blockSize; int newBlockSize = blockSize;
QTC_ASSERT(blockSize, return);
QTC_ASSERT((blockSize/m_bytesPerLine) * m_bytesPerLine == blockSize, QTC_ASSERT((blockSize/m_bytesPerLine) * m_bytesPerLine == blockSize,
blockSize = (blockSize/m_bytesPerLine + 1) * m_bytesPerLine); blockSize = (blockSize/m_bytesPerLine + 1) * m_bytesPerLine);
// Users can edit data in the range // Users can edit data in the range

View File

@@ -243,8 +243,10 @@ public:
bool setContents(const QByteArray &contents) override bool setContents(const QByteArray &contents) override
{ {
m_widget->clear(); m_widget->clear();
if (!contents.isEmpty()) {
m_widget->setSizes(0, contents.length(), contents.length()); m_widget->setSizes(0, contents.length(), contents.length());
m_widget->addData(0, contents); m_widget->addData(0, contents);
}
return true; return true;
} }