[PATCH] Fix crash when pressing down arrow at the end of the dive list

Dirk Hohndel dirk at hohndel.org
Tue May 7 06:45:18 PDT 2013


No, that's wrong. Instead add the missing check where it crashed (which
test did I miss...?). The UPDATE_TEXT macro already does the right thing
and quite a few of the other  The reason we DON'T want to simply return
is that we want to clear out the widget if no dive is selected (in which
case this will be called with -1 as argument.

/D

On Tue, 2013-05-07 at 08:40 +0200, subsurface at henrik.synth.no wrote:
> From: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>
> 
> MainTab::updateDiveInfo tried to operate on a nonexistent dive
> pointer from get_dive
> 
> Signed-off-by: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>
> ---
>  qt-ui/maintab.cpp | 30 ++++++++++++++----------------
>  1 file changed, 14 insertions(+), 16 deletions(-)
> 
> diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
> index 89501fc..12a526a 100644
> --- a/qt-ui/maintab.cpp
> +++ b/qt-ui/maintab.cpp
> @@ -82,31 +82,29 @@ void MainTab::updateDiveInfo(int dive)
>  	// the access is ui->objectName from here on.
>  	volume_t sacVal;
>  	struct dive *d = get_dive(dive);
> +
> +	if (!d) return;
> +
>  	UPDATE_TEXT(d, notes);
>  	UPDATE_TEXT(d, location);
>  	UPDATE_TEXT(d, suit);
>  	UPDATE_TEXT(d, divemaster);
>  	UPDATE_TEXT(d, buddy);
> -	if (d)
> -		ui->rating->setCurrentStars(d->rating);
> -	else
> -		ui->rating->setCurrentStars(0);
> +
> +	ui->rating->setCurrentStars(d->rating);
>  	ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE));
>  	ui->averageDepthText->setText(get_depth_string(d->meandepth, TRUE));
> -	sacVal.mliter = d ? d->sac : 0;
> +	sacVal.mliter = d->sac;
>  	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->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));
> +
> +	/* this is ALWAYS displayed in mbar */
> +	if (d->surface_pressure.mbar)
>  		ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar));
> -	else
> -		ui->airPressureText->setText(QString(""));
> -	if (d)
> -		ui->gasUsedText->setText(get_volume_string(get_gas_used(d), TRUE));
> -	else
> -		ui->gasUsedText->setText("");
> +
> +	ui->gasUsedText->setText(get_volume_string(get_gas_used(d), TRUE));
>  }
>  
>  void MainTab::on_addCylinder_clicked()




More information about the subsurface mailing list