|
|
Message-ID: <CABh_MKm9w3uXtQx4zHS1mOLLFK7=RViX86+DNtYmrNFr_8C+qQ@mail.gmail.com>
Date: Fri, 9 Dec 2016 07:16:42 +0100
From: Ed Schouten <ed@...i.nl>
To: musl@...ts.openwall.com
Subject: jrand48(): missing cast to int32_t?
Hi there,
According to POSIX, jrand48() is supposed to return a value between
[-2^31, 2^31). Musl's version of jrand48() is implemented as follows:
long jrand48(unsigned short s[3])
{
return __rand48_step(s, __seed48+3) >> 16;
}
Notice that the function only uses simple bit shifting and its return
type is long, meaning that on 64-bit systems, this implementation may
actually return a value between [0, 2^32).
For some reason, FreeBSD had the same bug. By adding a cast to
int32_t, its implementation now returns the same sequence of
pseudo-random numbers as macOS, Solaris, glibc, etc.
https://svnweb.freebsd.org/base?view=revision&revision=309650
Musl's version should likely be changed to this:
long jrand48(unsigned short s[3])
{
return (int32_t)(__rand48_step(s, __seed48+3) >> 16);
}
Best regards,
--
Ed Schouten <ed@...i.nl>
Nuxi, 's-Hertogenbosch, the Netherlands
KvK-nr.: 62051717
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.