mirror of
https://github.com/json-c/json-c.git
synced 2026-03-13 18:19:06 +08:00
Prevent signed overflow in get_time_seed
Casting time(2) return value to int and multiplying the result with such a constant will definitely lead to a signed overflow by this day. Since signed overflows are undefined behaviour in C, avoid this. Casting to unsigned is more than enough since the upper bits of a 64 bit time_t value will be removed with the int conversion anyway.
This commit is contained in:
@@ -305,7 +305,7 @@ static int get_time_seed(void)
|
|||||||
{
|
{
|
||||||
DEBUG_SEED("get_time_seed");
|
DEBUG_SEED("get_time_seed");
|
||||||
|
|
||||||
return (int)time(NULL) * 433494437;
|
return (unsigned)time(NULL) * 433494437;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* json_c_get_random_seed */
|
/* json_c_get_random_seed */
|
||||||
|
|||||||
Reference in New Issue
Block a user