This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: PATCH [4/n]: Support 64bit time_t and 32bit long
On 03/15/2012 01:17 PM, H.J. Lu wrote:
> days = *t / SECS_PER_DAY;
> + if (days != *t / SECS_PER_DAY)
> + goto overflow;
This is not a reliable way to test for integer overflow.
Since 'days' is signed, the compiler can assume that the
assignment does not overflow, and can ignore the 'if' entirely.
Instead, I suggest changing 'days' to be of type time_t,
so that overflow cannot occur here.
> @@ -65,6 +67,9 @@ __offtime (t, offset, tp)
> /* Guess a corrected year, assuming 365 days per year. */
> long int yg = y + days / 365 - (days % 365 < 0);
>
> + if (yg < 0)
> + goto overflow;
> +
Similarly here.