[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gpsd-dev] [PATCH] Improved resilience in gps_shm_close() in case it
From: |
Gary E. Miller |
Subject: |
Re: [gpsd-dev] [PATCH] Improved resilience in gps_shm_close() in case it is called after an unsuccessful gps_shm_open() |
Date: |
Tue, 2 Aug 2016 17:15:51 -0700 |
Yo Robert!
Patch applied. This fixes a nice hole.
I do find this mixing styles:
> + if (PRIVATE(gpsdata) && PRIVATE(gpsdata)->shmseg != NULL)
I would be happy with, simple TRUE/FALSE:
if (PRIVATE(gpsdata) && PRIVATE(gpsdata)->shmseg )
I think Eric prefers explicit comparisons, like this:
if (PRIVATE(gpsdata) != NULL && PRIVATE(gpsdata)->shmseg != NULL)
It does smoke out type errors now and then.
And when I do that, I prefer the constant on the LEFT side. I find
it allows the compiler to catch some non-obvious errors.
if ( NULL != PRIVATE(gpsdata) && NULL != PRIVATE(gpsdata)->shmseg)
But that drives Eric batty, so avoid that for now. :-)
On Mon, 1 Aug 2016 19:08:04 +0000
Robert Norris <address@hidden> wrote:
> Check that the structure exists before trying to use a component of
> it. ---
> libgps_shm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libgps_shm.c b/libgps_shm.c
> index b256249..e0aa3ab 100644
> --- a/libgps_shm.c
> +++ b/libgps_shm.c
> @@ -153,7 +153,7 @@ int gps_shm_read(struct gps_data_t *gpsdata)
>
> void gps_shm_close(struct gps_data_t *gpsdata)
> {
> - if (PRIVATE(gpsdata)->shmseg != NULL)
> + if (PRIVATE(gpsdata) && PRIVATE(gpsdata)->shmseg != NULL)
> (void)shmdt((const void *)PRIVATE(gpsdata)->shmseg);
> }
>
RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
address@hidden Tel:+1 541 382 8588
pgpWnPYd5BrdF.pgp
Description: OpenPGP digital signature