From 9666529b5a5be1fcde82caadc2fe2efa5ea81e49 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Wed, 16 Sep 2009 16:43:50 -0700 Subject: glx: Use initstate_r / random_r instead of corrupting global random number state Previously srandom and random were used. This cause the global random number generator state to be modified. This caused problems for applications that called srandom before calling into GLX. By using local state the global state is left unmodified. This should fix bug #23774. --- src/glx/x11/glxhash.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/glx/x11/glxhash.c b/src/glx/x11/glxhash.c index 74cd4f344d..7d28ada49c 100644 --- a/src/glx/x11/glxhash.c +++ b/src/glx/x11/glxhash.c @@ -87,9 +87,13 @@ #define HASH_ALLOC malloc #define HASH_FREE free -#define HASH_RANDOM_DECL -#define HASH_RANDOM_INIT(seed) srandom(seed) -#define HASH_RANDOM random() +#define HASH_RANDOM_DECL struct random_data rd; int32_t rv; char rs[256] +#define HASH_RANDOM_INIT(seed) \ + do { \ + (void) memset(&rd, 0, sizeof(rd)); \ + (void) initstate_r(seed, rs, sizeof(rs), &rd); \ + } while(0) +#define HASH_RANDOM ((void) random_r(&rd, &rv), rv) #define HASH_RANDOM_DESTROY typedef struct __glxHashBucket -- cgit v1.2.3