glx: Use initstate_r / random_r instead of corrupting global random number state
authorIan Romanick <ian.d.romanick@intel.com>
Wed, 16 Sep 2009 23:43:50 +0000 (16:43 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 16 Sep 2009 23:43:50 +0000 (16:43 -0700)
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

index 74cd4f344df613d305ecf09bf082ef7df760f1fb..7d28ada49ca776f3be946a8ecba3945fd60662b5 100644 (file)
 
 #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