Skip to content

Commit 42dbf00

Browse files
committed
CDRIVER-4234 Use arc4random_buf if available
Make arc4random_buf the first choice to use if it is available. Previously, if rand_r was not available, the older rand would be used even if arc4random_buf was available.
1 parent 64471fb commit 42dbf00

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/libbson/src/bson/bson-context.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,14 @@ static int32_t
225225
_get_rand (unsigned int *pseed)
226226
{
227227
int32_t result = 0;
228-
#ifndef BSON_HAVE_RAND_R
228+
#ifdef BSON_HAVE_ARC4RANDOM_BUF
229+
arc4random_buf (&result, sizeof (result));
230+
#elif defined(BSON_HAVE_RAND_R)
231+
result = rand_r (pseed);
232+
#else
229233
/* ms's runtime is multithreaded by default, so no rand_r */
230234
/* no rand_r on android either */
231235
result = rand ();
232-
#elif defined(BSON_HAVE_ARC4RANDOM_BUF)
233-
arc4random_buf (&result, sizeof (result));
234-
#else
235-
result = rand_r (pseed);
236236
#endif
237237
return result;
238238
}

0 commit comments

Comments
 (0)