From 90571432280a36f5e9ef5da468f832cf1d973f66 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Tue, 8 Mar 2016 16:54:12 +0200 Subject: 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 --- src/plugins/bineditor/bineditor.cpp | 1 + src/plugins/bineditor/bineditorplugin.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/plugins/bineditor') diff --git a/src/plugins/bineditor/bineditor.cpp b/src/plugins/bineditor/bineditor.cpp index 41d4155f46..ef3f2b31c4 100644 --- a/src/plugins/bineditor/bineditor.cpp +++ b/src/plugins/bineditor/bineditor.cpp @@ -376,6 +376,7 @@ bool BinEditorWidget::save(QString *errorString, const QString &oldFileName, con void BinEditorWidget::setSizes(quint64 startAddr, int range, int blockSize) { int newBlockSize = blockSize; + QTC_ASSERT(blockSize, return); QTC_ASSERT((blockSize/m_bytesPerLine) * m_bytesPerLine == blockSize, blockSize = (blockSize/m_bytesPerLine + 1) * m_bytesPerLine); // Users can edit data in the range diff --git a/src/plugins/bineditor/bineditorplugin.cpp b/src/plugins/bineditor/bineditorplugin.cpp index 1d686b5912..cce44ebebe 100644 --- a/src/plugins/bineditor/bineditorplugin.cpp +++ b/src/plugins/bineditor/bineditorplugin.cpp @@ -243,8 +243,10 @@ public: bool setContents(const QByteArray &contents) override { m_widget->clear(); - m_widget->setSizes(0, contents.length(), contents.length()); - m_widget->addData(0, contents); + if (!contents.isEmpty()) { + m_widget->setSizes(0, contents.length(), contents.length()); + m_widget->addData(0, contents); + } return true; } -- cgit v1.2.1