aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysdep.c
diff options
context:
space:
mode:
authorPaul Eggert2011-04-28 01:18:53 -0700
committerPaul Eggert2011-04-28 01:18:53 -0700
commitede49d7153ed628078bcbc2473f898904b5250ea (patch)
treeee55ad2109712fbc72489489490439ef6c31c039 /src/sysdep.c
parent2f30ecd05f7e5b9f78f256f75677530c501e5a6d (diff)
downloademacs-ede49d7153ed628078bcbc2473f898904b5250ea.tar.gz
emacs-ede49d7153ed628078bcbc2473f898904b5250ea.zip
* sysdep.c (get_random): Don't assume EMACS_INT is no wider than long.
Also, don't assume VALBITS / RAND_BITS is less than 5, and don't rely on undefined behavior when shifting a 1 left into the sign bit. * lisp.h (get_random): Change signature to match.
Diffstat (limited to 'src/sysdep.c')
-rw-r--r--src/sysdep.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index ca7de4f54bb..43f50cdb0a9 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1760,23 +1760,14 @@ seed_random (long int arg)
1760 * Build a full Emacs-sized word out of whatever we've got. 1760 * Build a full Emacs-sized word out of whatever we've got.
1761 * This suffices even for a 64-bit architecture with a 15-bit rand. 1761 * This suffices even for a 64-bit architecture with a 15-bit rand.
1762 */ 1762 */
1763long 1763EMACS_INT
1764get_random (void) 1764get_random (void)
1765{ 1765{
1766 long val = random (); 1766 EMACS_UINT val = 0;
1767#if VALBITS > RAND_BITS 1767 int i;
1768 val = (val << RAND_BITS) ^ random (); 1768 for (i = 0; i < (VALBITS + RAND_BITS - 1) / RAND_BITS; i++)
1769#if VALBITS > 2*RAND_BITS 1769 val = (val << RAND_BITS) ^ random ();
1770 val = (val << RAND_BITS) ^ random (); 1770 return val & (((EMACS_INT) 1 << VALBITS) - 1);
1771#if VALBITS > 3*RAND_BITS
1772 val = (val << RAND_BITS) ^ random ();
1773#if VALBITS > 4*RAND_BITS
1774 val = (val << RAND_BITS) ^ random ();
1775#endif /* need at least 5 */
1776#endif /* need at least 4 */
1777#endif /* need at least 3 */
1778#endif /* need at least 2 */
1779 return val & ((1L << VALBITS) - 1);
1780} 1771}
1781 1772
1782#ifndef HAVE_STRERROR 1773#ifndef HAVE_STRERROR