Re: [review v2] Use ctime_r and localtime_r if available

Andreas Schwab
2019-11-03T07:20:25Z

On Nov 02 2019, Christian Biesinger (Code Review) wrote:

> diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c
> index 67f9f3a..e0bad81 100644
> --- a/gdb/nat/linux-osdata.c
> +++ b/gdb/nat/linux-osdata.c
> @@ -912,7 +912,13 @@
> {
> time_t t = (time_t) seconds;
>
> - strncpy (time, ctime (&t), maxlen);
> + char buf[30];
> +#ifdef HAVE_CTIME_R
> + const char *time_str = ctime_r (&t, buf);
> +#else
> + const char *time_str = ctime (&t);
> +#endif

buf is unused if !HAVE_CTIME_R.

Note that both ctime and ctime_r are obsolescent and should be replaced
by strftime. gdb currently doesn't setlocale LC_TIME, but if it does it
would make the use of these functions undefined.

Andreas.

--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."