[PATCH] Fix crash on right click dive trip.

Dirk Hohndel dirk at hohndel.org
Wed May 8 12:16:59 PDT 2013


You don't check what's in git before you work on patches, do you? :-)

I already had something else committed, but I realized that you were
working in a cleaner direction so I took this patch, massaged it a bit
and added it on top of mine.

Please check the Qt branch to make sure I didn't break anything

/D

On Wed, 2013-05-08 at 19:38 +0100, amit.k.chaudhuri at gmail.com wrote:
> From: Amit Chaudhuri <amit.k.chaudhuri at gmail.com>
> 
> 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.
> 
> Signed-off-by: Amit Chaudhuri <amit.k.chaudhuri at gmail.com>
> ---
>  qt-ui/maintab.cpp |   28 +++++++++++++++++++++-------
>  1 file changed, 21 insertions(+), 7 deletions(-)
> 
> diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
> index 89501fc..3734aba 100644
> --- a/qt-ui/maintab.cpp
> +++ b/qt-ui/maintab.cpp
> @@ -91,13 +91,27 @@ void MainTab::updateDiveInfo(int dive)
>  		ui->rating->setCurrentStars(d->rating);
>  	else
>  		ui->rating->setCurrentStars(0);
> -	ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE));
> -	ui->averageDepthText->setText(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) {
> +		ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE));
> +		ui->averageDepthText->setText(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) : "");
> +	} else {
> +		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());
> +	}
>  	if (d && d->surface_pressure.mbar)
>  		/* this is ALWAYS displayed in mbar */
>  		ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar));




More information about the subsurface mailing list