Browse Source

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.
tags/json-c-0.16-20220414
Tobias Stoeckmann 5 years ago
parent
commit
df62119b7f
1 changed files with 1 additions and 1 deletions
  1. +1
    -1
      random_seed.c

+ 1
- 1
random_seed.c View File

@@ -305,7 +305,7 @@ static int get_time_seed(void)
{
DEBUG_SEED("get_time_seed");

return (int)time(NULL) * 433494437;
return (unsigned)time(NULL) * 433494437;
}

/* json_c_get_random_seed */


Loading…
Cancel
Save