Dax89/QHexView

Crash in ReplaceCommand::redo

SimonKagstrom opened this issue · 7 comments

After updating the git repo, I now get crashes in ReplaceCommand::redo because this->_inscmd or this->_remcmd is null (as returned by internalInsert (or internalRemove).

I've added null-checks for the result, which fixes the crash but my hexedits are completely empty after this.

I might be using it in the wrong way, an example is this function:

https://github.com/SimonKagstrom/emilpro/blob/master/src/qt/emilpro/mainwindow.cpp#L640

Starting from this commit: 2a662d4

I have rewrited QHexEditData from scratch in order to support big files (and generic QIODevice objects too).
Now, QHexEditData's constructor is private, and you can load a generic I/O Device or an In-Memory buffer using these three methods:

  • QHexEditData::fromFile()
  • QHexEditData::fromBuffer()
  • QHexEditData::fromDevice()

By looking at your source code, I have seen in setupInstructionEncoding() method these lines of code:

void MainWindow::setupInstructionEncoding()
{
    char buf[32];
    memset(buf, 0, sizeof(buf));

    QBuffer *encodingBuffer;

    encodingBuffer = new QBuffer();
    encodingBuffer->open(QBuffer::ReadWrite);
    encodingBuffer->write(buf, sizeof(buf));

    m_encodingData = new QHexEditData(encodingBuffer);

   ...
}

which can be rewritten as:

void MainWindow::setupInstructionEncoding()
{
    /* Create a buffer with length = 32, and fill it with 0x00 */
    QByteArray buf(32, 0x00);

    /* Associate this buffer with QHexEditData, and take the ownership */
    m_encodingData = QHexEditData::fromBuffer(buf);

   ...
}

OK, good to hear - I'll take a look at that.

That said, since internalInsert and internalRemove can return NULL, so I think it would be good to check the return value from them.

With the fromBuffer() stuff, I can now compile, but I still get the crash.

What I do is basically

void MainWindow::setupInstructionEncoding()
{
    QByteArray buf(32, 0x0);

    m_encodingData = QHexEditData::fromMemory(buf);
        [...]
    m_encodingHexEdit = new QHexEdit(m_ui->instructionEncodingLineEdit);
    m_encodingHexEdit->setData(m_encodingData);
}

void MainWindow::updateInstructionEncoding(const IInstruction* insn)
{
    uint8_t buf[32];

        [... fill in buf]
    m_encodingData->replace(0, 32, QByteArray((const char *)buf, sizeof(buf)));
}

where updateInstructionEncoding is called to fill in the current position. I get a crash in replace(), and get the same behavior when using remove() + insert().

Ok, I can reproduce this bug, I will fix it in short time!
Sorry for this issue :)

The commit e7eb910 should fix the bug.

Let me know if it works now.

Yes, after that commit it works again.

Thanks!

On Sat, Jan 18, 2014 at 6:35 PM, Antonio Davide notifications@github.comwrote:

The commit e7eb910e7eb91051706c3e02a02e979d6e9b02cc8fcc729should fix the bug.

Let me know if it works now.


Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-32687448
.

Great!