]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix 'random' on MS-Windows when integers are wider than 30 bits
authorEli Zaretskii <eliz@gnu.org>
Sat, 14 Aug 2021 14:39:38 +0000 (17:39 +0300)
committerEli Zaretskii <eliz@gnu.org>
Sat, 14 Aug 2021 14:39:38 +0000 (17:39 +0300)
* src/w32.c (random): Provide more random bits for MS-Windows
builds with EMACS_INT that is wider than 32 bits.  (Bug#32605)

src/w32.c

index 968b4bbe4890cd3347efe5b50fb3d914dd542ab0..180c73aa0f057ad6f21e6e3c6b763f961ef19b0b 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -2389,8 +2389,13 @@ rand_as183 (void)
 int
 random (void)
 {
-  /* rand_as183 () gives us 15 random bits...hack together 30 bits.  */
+  /* rand_as183 () gives us 15 random bits...hack together 30 bits for
+     Emacs with 32-bit EMACS_INT, and at least 31 bit for wider EMACS_INT.  */
+#if EMACS_INT_MAX > INT_MAX
+  return ((rand_as183 () << 30) | (rand_as183 () << 15) | rand_as183 ());
+#else
   return ((rand_as183 () << 15) | rand_as183 ());
+#endif
 }
 
 void