[PATCH] Remove harmful casts in gmtime_r()

Corinna Vinschen vinschen@redhat.com
Thu Sep 7 13:38:00 GMT 2017


On Sep  7 15:10, Sebastian Huber wrote:
> In case time_t is long, then the cast to long is a nop.  In case time_t
> is __int_least64_t, then the cast to long may truncate the value before
> the division.
> 
> Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
> ---
>  newlib/libc/time/gmtime_r.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/newlib/libc/time/gmtime_r.c b/newlib/libc/time/gmtime_r.c
> index 81c7c94b1..6475df3ba 100644
> --- a/newlib/libc/time/gmtime_r.c
> +++ b/newlib/libc/time/gmtime_r.c
> @@ -56,8 +56,8 @@ _DEFUN (gmtime_r, (tim_p, res),
>    unsigned erayear, yearday, month, day;
>    unsigned long eraday;
>  
> -  days = ((long)lcltime) / SECSPERDAY + EPOCH_ADJUSTMENT_DAYS;
> -  rem = ((long)lcltime) % SECSPERDAY;
> +  days = lcltime / SECSPERDAY + EPOCH_ADJUSTMENT_DAYS;
> +  rem = lcltime % SECSPERDAY;
>    if (rem < 0)
>      {
>        rem += SECSPERDAY;
> -- 
> 2.12.3

Please push.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20170907/3c401a36/attachment.sig>


More information about the Newlib mailing list