prevent integer overflow on 32 bit

On 32 bit machine timespec->tv_sec (time_t) is 32 bit.
Also 1000 * 1000 * 1000 is 32 bit.
The multiplication of 2 32 bit integers gives a 32 bit integer, however
this can overflow.
Converting the first factor to 64 bit before the multiplication solves
the issue.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
Frediano Ziglio 2015-08-21 10:21:46 +01:00
parent 6001d8905e
commit 068bf4e83d

View File

@ -164,7 +164,7 @@ static void rendering_incorrect(const char *msg)
static inline red_time_t timespec_to_red_time(struct timespec *time)
{
return time->tv_sec * (1000 * 1000 * 1000) + time->tv_nsec;
return (red_time_t) time->tv_sec * (1000 * 1000 * 1000) + time->tv_nsec;
}
static clockid_t clock_id;