From b5d5b05140eac7a8031cdb15e7c31f659a6f2da6 Mon Sep 17 00:00:00 2001 From: Amit Chaudhuri Date: Wed, 8 May 2013 12:08:00 -0700 Subject: Fix crash on right click dive trip A null pointer dereference occured after right click on a dive trip because updateDiveInfo was called with dive == -1 causing get_dive(int) to return null. Wrap to avoid crash and clear dive info widget text labels. [Dirk Hohndel: this is different from the fix I had committed earlier; I decided to combine the ideas, clean this one up a bit more and this is the result] Signed-off-by: Amit Chaudhuri Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 078d59ca9..4e7f6b3a1 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -87,26 +87,39 @@ void MainTab::updateDiveInfo(int dive) UPDATE_TEXT(d, suit); UPDATE_TEXT(d, divemaster); UPDATE_TEXT(d, buddy); - if (d) + if (d) { ui->rating->setCurrentStars(d->rating); - else - ui->rating->setCurrentStars(0); - ui->maximumDepthText->setText(d ? get_depth_string(d->maxdepth, TRUE) : ""); - ui->averageDepthText->setText(d ? get_depth_string(d->meandepth, TRUE) : ""); - sacVal.mliter = d ? d->sac : 0; - ui->sacText->setText(get_volume_string(sacVal, TRUE).append("/min")); - ui->otuText->setText(QString("%1").arg( d ? d->otu : 0)); - ui->waterTemperatureText->setText(d ? get_temperature_string(d->watertemp, TRUE) : ""); - ui->airTemperatureText->setText(d ? get_temperature_string(d->airtemp, TRUE) : ""); - if (d && d->surface_pressure.mbar) - /* this is ALWAYS displayed in mbar */ - ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar)); - else - ui->airPressureText->setText(QString("")); - if (d) + ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE)); + ui->averageDepthText->setText(get_depth_string(d->meandepth, TRUE)); + ui->otuText->setText(QString("%1").arg(d->otu)); + ui->waterTemperatureText->setText(get_temperature_string(d->watertemp, TRUE)); + ui->airTemperatureText->setText(get_temperature_string(d->airtemp, TRUE)); ui->gasUsedText->setText(get_volume_string(get_gas_used(d), TRUE)); - else - ui->gasUsedText->setText(""); + if ((sacVal.mliter = d->sac) > 0) + ui->sacText->setText(get_volume_string(sacVal, TRUE).append("/min")); + else + ui->sacText->setText(QString()); + if (d->surface_pressure.mbar) + /* this is ALWAYS displayed in mbar */ + ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar)); + else + ui->airPressureText->setText(QString()); + } else { + ui->rating->setCurrentStars(0); + ui->sacText->setText(QString()); + ui->otuText->setText(QString()); + ui->oxygenHeliumText->setText(QString()); + ui->dateText->setText(QString()); + ui->diveTimeText->setText(QString()); + ui->surfaceIntervalText->setText(QString()); + ui->maximumDepthText->setText(QString()); + ui->averageDepthText->setText(QString()); + ui->visibilityText->setText(QString()); + ui->waterTemperatureText->setText(QString()); + ui->airTemperatureText->setText(QString()); + ui->gasUsedText->setText(QString()); + ui->airPressureText->setText(QString()); + } } void MainTab::on_addCylinder_clicked() -- cgit v1.2.3-70-g09d2