From 0c69988f837f30726f92b604967237eeee746b2a Mon Sep 17 00:00:00 2001 From: "C. Balles" Date: Sun, 9 Apr 2017 04:49:16 +0200 Subject: [PATCH] Fix sidebar crash (#99) * Fix crash on invalid asm/hex Added nullptr checks because the called functions can (and will) return NULL * Call disassemble when hex2asm is clicked * Change order on != comparison * Fix missing whitspace --- src/qrcore.cpp | 6 +++--- src/widgets/sidebar.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qrcore.cpp b/src/qrcore.cpp index c337ea09..aa15313e 100644 --- a/src/qrcore.cpp +++ b/src/qrcore.cpp @@ -511,14 +511,14 @@ void QRCore::setDefaultCPU() { QString QRCore::assemble(const QString &code) { RAsmCode *ac = r_asm_massemble (core->assembler, code.toUtf8().constData()); - QString hex = QString(ac->buf_hex); + QString hex(ac != nullptr ? ac->buf_hex : ""); r_asm_code_free (ac); return hex; } QString QRCore::disassemble(const QString &hex) { RAsmCode *ac = r_asm_mdisassemble_hexstr(core->assembler, hex.toUtf8().constData()); - QString code = QString (ac->buf_asm); + QString code = QString (ac != nullptr ? ac->buf_asm : ""); r_asm_code_free (ac); return code; } @@ -540,7 +540,7 @@ int QRCore::get_size() { RBinObject *obj = r_bin_get_object(core->bin); //return obj->size; - return obj->obj_size; + return obj != nullptr ? obj->obj_size : 0; } ulong QRCore::get_baddr() diff --git a/src/widgets/sidebar.cpp b/src/widgets/sidebar.cpp index bec3fdb6..ed6312fb 100644 --- a/src/widgets/sidebar.cpp +++ b/src/widgets/sidebar.cpp @@ -89,7 +89,7 @@ void SideBar::on_asm2hex_clicked() void SideBar::on_hex2asm_clicked() { - ui->asmInput->setPlainText(main->core->assemble(ui->hexInput->toPlainText())); + ui->asmInput->setPlainText(main->core->disassemble(ui->hexInput->toPlainText())); } void SideBar::on_respButton_toggled(bool checked)