[Pkg-shadow-devel] Bug#1032393: Bug#1032393: [PATCH v2 2/2] debian/control: Add libbsd-dev and pkg-config

Alejandro Colomar alx.manpages at gmail.com
Sat Mar 11 21:31:28 GMT 2023


Hi Paul,

On 3/11/23 20:29, Paul Eggert wrote:
> From 1c8388d1d1831e976cdaa6e6f27bb08bf31aedc5 Mon Sep 17 00:00:00 2001
> From: Paul Eggert <eggert at cs.ucla.edu>
> Date: Sat, 11 Mar 2023 00:42:29 -0800
> Subject: [PATCH 4/6] Fix crash with large timestamps
> 
> * libmisc/date_to_str.c (date_to_str): Do not crash if gmtime
> returns NULL because the timestamp is far in the future.

Thanks :)

> Instead, use a dummy struct tm * to pacify any pedantic runtime.
> Simplify by always calling strftime, instead of sometimes strftime
> and sometimes strlcpy.
> 
> Signed-off-by: Paul Eggert <eggert at cs.ucla.edu>
> ---
>  libmisc/date_to_str.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/libmisc/date_to_str.c b/libmisc/date_to_str.c
> index f3b9dc76..4b3a4f48 100644
> --- a/libmisc/date_to_str.c
> +++ b/libmisc/date_to_str.c
> @@ -35,13 +35,12 @@
>  
>  void date_to_str (size_t size, char buf[size], long date)
>  {
> -	time_t t;
> +	time_t t = date;
> +	struct tm *tm = gmtime (&t);
> +	struct tm dummy;
>  
> -	t = date;
> -	if (date < 0) {
> -		(void) strlcpy (buf, "never", size);
> -	} else {
> -		(void) strftime (buf, size, "%Y-%m-%d", gmtime (&t));
> -		buf[size - 1] = '\0';
> -	}
> +	(void) strftime (buf, size,
> +			 date < 0 ? "never" : tm ? "%Y-%m-%d" : "future",
> +			 tm ? tm : &dummy);

What's this &dummy exactly for?

Cheers,

Alex

> +	buf[size - 1] = '\0';
>  }
> -- 
> 2.37.2
> 


-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://alioth-lists.debian.net/pipermail/pkg-shadow-devel/attachments/20230311/349d9f27/attachment.sig>


More information about the Pkg-shadow-devel mailing list