Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20170621003415.GY1627@brightrain.aerifal.cx>
Date: Tue, 20 Jun 2017 20:34:15 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] Handle localtime errors in ctime

On Thu, Jun 15, 2017 at 08:46:18PM +0300, Alexander Monakov wrote:
> On Thu, 15 Jun 2017, Rich Felker wrote:
> > Look ok?
> > 
> > diff --git a/src/time/ctime_r.c b/src/time/ctime_r.c
> > index d2260a1..05699ca 100644
> > --- a/src/time/ctime_r.c
> > +++ b/src/time/ctime_r.c
> > @@ -3,6 +3,5 @@
> >  char *ctime_r(const time_t *t, char *buf)
> >  {
> >  	struct tm tm;
> > -	localtime_r(t, &tm);
> > -	return asctime_r(&tm, buf);
> > +	return localtime_r(t, &tm) ? asctime_r(&tm, buf) : 0;
> >  }
> 
> Sure, although personally I'm highly tempted to pick up the size optimization
> from reusing return value of localtime_r:
> 
> Alexander
> 
> diff --git a/src/time/ctime_r.c b/src/time/ctime_r.c
> index d2260a16..9047b38f 100644
> --- a/src/time/ctime_r.c
> +++ b/src/time/ctime_r.c
> @@ -2,7 +2,6 @@
>  
>  char *ctime_r(const time_t *t, char *buf)
>  {
> -	struct tm tm;
> -	localtime_r(t, &tm);
> -	return asctime_r(&tm, buf);
> +	struct tm tm, *tm_p;
> +	return (tm_p = localtime_r(t, &tm)) ? asctime_r(tm_p, buf) : 0;
>  }

OK, using this one with a minor change to make it more readable (at
least to me).

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.