Fix null deref (#101)

* Fix null deref when QStringList is empty

* Indent memory widget
This commit is contained in:
Sergi Àlvarez i Capilla 2017-04-09 19:09:52 +02:00 committed by Duncan Ogilvie
parent 7c63a67575
commit b7c3929d5e

View File

@ -461,9 +461,12 @@ void MemoryWidget::refreshDisasm(QString off = "") {
QTextCursor tc = this->disasTextEdit->textCursor(); QTextCursor tc = this->disasTextEdit->textCursor();
tc.select( QTextCursor::LineUnderCursor ); tc.select( QTextCursor::LineUnderCursor );
QString lastline = tc.selectedText(); QString lastline = tc.selectedText();
QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; QStringList elements = lastline.split(" ", QString::SkipEmptyParts);
if (ele.contains("0x")) { if (elements.length() > 0) {
this->main->core->cmd("s " + ele); QString ele = elements[0];
if (ele.contains("0x")) {
this->main->core->cmd("s " + ele);
}
} }
} }
@ -959,7 +962,7 @@ void MemoryWidget::on_actionSettings_menu_1_triggered()
{ {
bool ok = true; bool ok = true;
// QFont font = QFont("Monospace", 8); // QFont font = QFont("Monospace", 8);
QFont font = QFontDialog::getFont( &ok, ui->disasTextEdit_2->font(), this); QFont font = QFontDialog::getFont( &ok, ui->disasTextEdit_2->font(), this);
setFonts (font); setFonts (font);
@ -1566,54 +1569,54 @@ void MemoryWidget::on_previewToolButton_2_clicked()
} }
bool MemoryWidget::eventFilter(QObject *obj, QEvent *event) { bool MemoryWidget::eventFilter(QObject *obj, QEvent *event) {
if (event->type() == QEvent::Resize && obj == this && this->isVisible()) { if (event->type() == QEvent::Resize && obj == this && this->isVisible()) {
if (this->main->responsive) { if (this->main->responsive) {
QResizeEvent *resizeEvent = static_cast<QResizeEvent*>(event); QResizeEvent *resizeEvent = static_cast<QResizeEvent*>(event);
//qDebug("Dock Resized (New Size) - Width: %d Height: %d", //qDebug("Dock Resized (New Size) - Width: %d Height: %d",
// resizeEvent->size().width(), // resizeEvent->size().width(),
// resizeEvent->size().height()); // resizeEvent->size().height());
if (resizeEvent->size().width() <= 1150) { if (resizeEvent->size().width() <= 1150) {
ui->frame_3->setVisible(false); ui->frame_3->setVisible(false);
ui->memPreviewTab->setVisible(false); ui->memPreviewTab->setVisible(false);
ui->previewToolButton_2->setChecked(false); ui->previewToolButton_2->setChecked(false);
if (resizeEvent->size().width() <= 950) { if (resizeEvent->size().width() <= 950) {
ui->memSideTabWidget_2->hide(); ui->memSideTabWidget_2->hide();
ui->hexSideTab_2->hide(); ui->hexSideTab_2->hide();
ui->memSideToolButton->setChecked(true); ui->memSideToolButton->setChecked(true);
} else { } else {
ui->memSideTabWidget_2->show(); ui->memSideTabWidget_2->show();
ui->hexSideTab_2->show(); ui->hexSideTab_2->show();
ui->memSideToolButton->setChecked(false); ui->memSideToolButton->setChecked(false);
} }
} else { } else {
ui->frame_3->setVisible(true); ui->frame_3->setVisible(true);
ui->memPreviewTab->setVisible(true); ui->memPreviewTab->setVisible(true);
ui->previewToolButton_2->setChecked(true); ui->previewToolButton_2->setChecked(true);
} }
} }
} else if ((obj == ui->disasTextEdit_2 || obj==ui->disasTextEdit_2->viewport()) && event->type() == QEvent::MouseButtonDblClick) { } else if ((obj == ui->disasTextEdit_2 || obj==ui->disasTextEdit_2->viewport()) && event->type() == QEvent::MouseButtonDblClick) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
//qDebug()<<QString("Click location: (%1,%2)").arg(mouseEvent->x()).arg(mouseEvent->y()); //qDebug()<<QString("Click location: (%1,%2)").arg(mouseEvent->x()).arg(mouseEvent->y());
QTextCursor cursor = ui->disasTextEdit_2->cursorForPosition( QPoint(mouseEvent->x(), mouseEvent->y()) ); QTextCursor cursor = ui->disasTextEdit_2->cursorForPosition( QPoint(mouseEvent->x(), mouseEvent->y()) );
cursor.select( QTextCursor::LineUnderCursor ); cursor.select( QTextCursor::LineUnderCursor );
QString lastline = cursor.selectedText(); QString lastline = cursor.selectedText();
QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; QString ele = lastline.split(" ", QString::SkipEmptyParts)[0];
if (ele.contains("0x")) { if (ele.contains("0x")) {
QString jump = ""; QString jump = "";
jump = this->main->core->getOffsetJump(ele); jump = this->main->core->getOffsetJump(ele);
if (jump != "") { if (jump != "") {
if (jump.contains("0x")) { if (jump.contains("0x")) {
QString fcn = this->main->core->cmdFunctionAt(jump); QString fcn = this->main->core->cmdFunctionAt(jump);
if (fcn != "") { if (fcn != "") {
this->main->seek(jump.trimmed(), fcn); this->main->seek(jump.trimmed(), fcn);
} }
} else { } else {
this->main->seek(this->main->core->cmd("?v " + jump), jump); this->main->seek(this->main->core->cmd("?v " + jump), jump);
} }
} }
} }
} }
return QDockWidget::eventFilter(obj, event); return QDockWidget::eventFilter(obj, event);
} }
void MemoryWidget::on_actionXRefs_triggered() void MemoryWidget::on_actionXRefs_triggered()