Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in ReplaceCommand::redo #3

Closed
SimonKagstrom opened this issue Jan 15, 2014 · 7 comments
Closed

Crash in ReplaceCommand::redo #3

SimonKagstrom opened this issue Jan 15, 2014 · 7 comments
Assignees
Labels

Comments

@SimonKagstrom
Copy link

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

@Dax89
Copy link
Owner

Dax89 commented Jan 16, 2014

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);

   ...
}

@SimonKagstrom
Copy link
Author

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.

@ghost ghost assigned Dax89 Jan 17, 2014
@SimonKagstrom
Copy link
Author

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().

@Dax89
Copy link
Owner

Dax89 commented Jan 18, 2014

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

@Dax89
Copy link
Owner

Dax89 commented Jan 18, 2014

The commit e7eb910 should fix the bug.

Let me know if it works now.

@SimonKagstrom
Copy link
Author

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
.

@Dax89
Copy link
Owner

Dax89 commented Jan 18, 2014

Great!

@Dax89 Dax89 closed this as completed Jan 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants