On Mon, Mar 16, 2015 at 08:02:52PM +0100, Jan Darowski wrote:
> From 36bfb9a7303748caf6da3cf747a029476d971460 Mon Sep 17 00:00:00 2001
> From: Jan Darowski <[email protected]>
> Date: Mon, 16 Mar 2015 19:48:55 +0100
> Subject: [PATCH] Fixed dive_set_geodata_from_picture segfault.
> 
> Segfault did appear when picture had some gps coordinates but
> there was no dive site assigned to the dive.
> 
> Signed-off-by: Jan Darowski <[email protected]>
> ---
>  dive.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/dive.c b/dive.c
> index afa38e4..ce682bc 100644
> --- a/dive.c
> +++ b/dive.c
> @@ -2951,7 +2951,7 @@ unsigned int dive_get_picture_count(struct dive *d)
>  void dive_set_geodata_from_picture(struct dive *d, struct picture *pic)
>  {
>       struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid);
> -     if (!dive_site_has_gps_location(ds) && (pic->latitude.udeg || 
> pic->longitude.udeg)) {
> +     if (ds && !dive_site_has_gps_location(ds) && (pic->latitude.udeg || 
> pic->longitude.udeg)) {

Argl. dive_site_has_gps_location does the right thing when ds is NULL, but
of course it will correctly respond that NULL has no gps location and then
the test will succeed and we'll dereference ds in the next line...

>               ds->latitude = pic->latitude;
>               ds->longitude = pic->longitude;

Great catch.

Thanks

/D
_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to