fix mrand48/jrand48 return value on 64-bit archs
authorRich Felker <dalias@aerifal.cx>
Sat, 17 Dec 2016 04:19:27 +0000 (23:19 -0500)
committerRich Felker <dalias@aerifal.cx>
Sat, 17 Dec 2016 04:23:10 +0000 (23:23 -0500)
POSIX specifies the result to have signed 32-bit range. on 32-bit
archs, the implicit conversion to long achieved the desired range
already, but when long is 64-bit, a cast is needed.

patch by Ed Schouten.

src/prng/mrand48.c

index ee650fc..0519d66 100644 (file)
@@ -6,7 +6,7 @@ extern unsigned short __seed48[7];
 
 long jrand48(unsigned short s[3])
 {
-       return __rand48_step(s, __seed48+3) >> 16;
+       return (int32_t)(__rand48_step(s, __seed48+3) >> 16);
 }
 
 long mrand48(void)