On 2020-04-19 17:35:50 -0400, Remco Rijnders wrote:
> For the same future consideration, please find attached a proposed patch.
> Deterministic it is not (unless you want to save the seed and a message
> counter somewhere), guaranteed to be unique, it is.

Well... If you have

+#if RAND_MAX/256 >= 0xFFFFFFFFFFFFFF

this means that you consider that a RAND_MAX value may have more
than 64 bits. Though unlikely, this is obviously allowed by the
C standard. But in this case, you have a possible integer overflow
here (e.g. if RAND_MAX is a signed 128-bit integer):

    r = r*(RAND_MAX + (uint64_t) 1) + random();

Since you're interested only in a 64-bit unsigned number, this
should be:

    r = r * ((uint64_t) RAND_MAX + (uint64_t) 1) + (uint64_t) random();

-- 
Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Reply via email to