diff options
author | Amit Chaudhuri <amit.k.chaudhuri@gmail.com> | 2013-05-08 12:08:00 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-05-08 12:10:51 -0700 |
commit | b5d5b05140eac7a8031cdb15e7c31f659a6f2da6 (patch) | |
tree | d26741d03b8cb625b8ef00e877a3f1b900bc8224 /qt-ui/maintab.cpp | |
parent | 661aa67e89ad7710f90482b074715c4d1448860a (diff) | |
download | subsurface-b5d5b05140eac7a8031cdb15e7c31f659a6f2da6.tar.gz |
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 <amit.k.chaudhuri@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/maintab.cpp')
-rw-r--r-- | qt-ui/maintab.cpp | 49 |
1 files 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() |