> The variables could have more meaningful names, also the reuse of
> variable "gt" looks hackish, but the current code looks correct to me.
> 
> Does the diff below make things clearer?

It does. After reading the current code again a few times, it is
as well clear. Incredible how I couldn't see it before.
My apologies! And many thanks for the helpful replies to you and Otto!

Holger

> 
> --- privsep.c.~1.53.~ Sat May 11 14:17:40 2019
> +++ privsep.c Sat May 11 14:20:30 2019
> @@ -724,10 +724,12 @@ struct  tm *
>  priv_localtime(const time_t *t)
>  {
>       static struct tm lt, gt0;
> -     static struct tm *gt = NULL;
>       static char zone[PATH_MAX];
> +     static int cached = 0;
>  
> -     if (gt != NULL) {
> +     if (cached) {
> +             struct tm *gt;
> +
>               gt = gmtime(t);
>               gt0.tm_sec = gt->tm_sec;
>               gt0.tm_zone = gt->tm_zone;
> @@ -749,7 +751,7 @@ priv_localtime(const time_t *t)
>               lt.tm_zone = NULL;
>  
>       gt0.tm_zone = NULL;
> -     gt = &gt0;
> +     cached = 1;
>  
>       return <
>  }
> 
> -- 
> jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to