aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/libxml/patches/rand.patch
blob: 76e95079f18c4fc3158318c606e428a28b6bff35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
commit 9d4379ac1a951a46959c7c02fdca2df237ef475e
author: eninng
date: 2022-05-12T17:48:42+03:00

    [libxml] Use thread_local rand_seed when rand_r is avaliable
    
    Task: SK-6086

--- a/dict.c	(f4373e5855353e6a2cbee8bda5d59c20f67e14c7)
+++ b/dict.c	(9d4379ac1a951a46959c7c02fdca2df237ef475e)
@@ -142,9 +142,9 @@ static int xmlDictInitialized = 0;
 #ifdef DICT_RANDOMIZATION
 #ifdef HAVE_RAND_R
 /*
- * Internal data for random function, protected by xmlDictMutex
+ * Internal data for random function
  */
-static unsigned int rand_seed = 0;
+static _Thread_local unsigned int rand_seed = 0;
 #endif
 #endif
 
@@ -182,10 +182,7 @@ int __xmlInitializeDict(void) {
     xmlRMutexLock(xmlDictMutex);
 
 #ifdef DICT_RANDOMIZATION
-#ifdef HAVE_RAND_R
-    rand_seed = time(NULL);
-    rand_r(& rand_seed);
-#else
+#ifndef HAVE_RAND_R
     srand(time(NULL));
 #endif
 #endif
@@ -201,13 +198,15 @@ int __xmlRandom(void) {
     if (xmlDictInitialized == 0)
         __xmlInitializeDict();
 
-    xmlRMutexLock(xmlDictMutex);
 #ifdef HAVE_RAND_R
+    if (rand_seed == 0)
+        rand_seed = time(NULL);
     ret = rand_r(& rand_seed);
 #else
+    xmlRMutexLock(xmlDictMutex);
     ret = rand();
-#endif
     xmlRMutexUnlock(xmlDictMutex);
+#endif
     return(ret);
 }
 #endif