aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/lisp.h2
-rw-r--r--src/sysdep.c21
3 files changed, 13 insertions, 16 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 2bda5ffa46f..40fb601e061 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,11 @@
12011-04-28 Paul Eggert <eggert@cs.ucla.edu> 12011-04-28 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 * sysdep.c (get_random): Don't assume EMACS_INT is no wider than long.
4 Also, don't assume VALBITS / RAND_BITS is less than 5,
5 and don't rely on undefined behavior when shifting a 1 left into
6 the sign bit.
7 * lisp.h (get_random): Change signature to match.
8
3 * lread.c (hash_string): Use size_t, not int, for hash computation. 9 * lread.c (hash_string): Use size_t, not int, for hash computation.
4 Normally we prefer signed values; but hashing is special, because 10 Normally we prefer signed values; but hashing is special, because
5 it's better to use unsigned division on hash table sizes so that 11 it's better to use unsigned division on hash table sizes so that
diff --git a/src/lisp.h b/src/lisp.h
index 625027769cf..dca3b4d9a32 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3353,7 +3353,7 @@ extern void flush_pending_output (int);
3353extern void child_setup_tty (int); 3353extern void child_setup_tty (int);
3354extern void setup_pty (int); 3354extern void setup_pty (int);
3355extern int set_window_size (int, int, int); 3355extern int set_window_size (int, int, int);
3356extern long get_random (void); 3356extern EMACS_INT get_random (void);
3357extern void seed_random (long); 3357extern void seed_random (long);
3358extern int emacs_open (const char *, int, int); 3358extern int emacs_open (const char *, int, int);
3359extern int emacs_close (int); 3359extern int emacs_close (int);
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