From: Ondřej Surý Date: Wed, 30 May 2018 05:03:35 +0000 (+0200) Subject: Change the _LOCK macro on Windows and the variable initialization to be more VC compa... X-Git-Tag: v9.13.1~21^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=430e8d68580c18fea90f176e184f1ebc99053621;p=thirdparty%2Fbind9.git Change the _LOCK macro on Windows and the variable initialization to be more VC compatible --- diff --git a/lib/isc/random.c b/lib/isc/random.c index f74a08665b9..9e78878170a 100644 --- a/lib/isc/random.c +++ b/lib/isc/random.c @@ -92,15 +92,15 @@ isc_random32(void) { void isc_random_buf(void *buf, size_t buflen) { + int i; + isc_uint32_t r; + REQUIRE(buf); REQUIRE(buflen > 0); RUNTIME_CHECK(isc_once_do(&isc_random_once, isc_random_initialize) == ISC_R_SUCCESS); - int i; - isc_uint32_t r; - for (i = 0; i + sizeof(r) <= buflen; i += sizeof(r)) { r = next(); memmove((uint8_t *)buf + i, &r, sizeof(r)); /* Buffers cannot diff --git a/lib/isc/xoshiro128starstar.c b/lib/isc/xoshiro128starstar.c index a737bfd91c8..e2466dd54cb 100644 --- a/lib/isc/xoshiro128starstar.c +++ b/lib/isc/xoshiro128starstar.c @@ -44,14 +44,17 @@ static volatile HANDLE _mutex = NULL; * will attempt to allocate a mutex and compare-and-swap it into place as the * global mutex. On failure to swap in the global mutex, the mutex is closed. */ -#define _LOCK() { \ - if (!_mutex) { \ - HANDLE p = CreateMutex(NULL, FALSE, NULL); \ - if (InterlockedCompareExchangePointer((void **)&_mutex, (void *)p, NULL)) \ - CloseHandle(p); \ - } \ - WaitForSingleObject(_mutex, INFINITE); \ -} +#define _LOCK() \ + do { \ + if (!_mutex) { \ + HANDLE p = CreateMutex(NULL, FALSE, NULL); \ + if (InterlockedCompareExchangePointer \ + ((void **)&_mutex, (void *)p, NULL)) { \ + CloseHandle(p); \ + } \ + } \ + WaitForSingleObject(_mutex, INFINITE); \ + } while (0) #define _UNLOCK() ReleaseMutex(_mutex) @@ -75,11 +78,12 @@ static isc_uint32_t seed[4]; static inline isc_uint32_t next(void) { - _LOCK(); + isc_uint32_t result_starstar, t; - const isc_uint32_t result_starstar = rotl(seed[0] * 5, 7) * 9; + _LOCK(); - const isc_uint32_t t = seed[1] << 9; + result_starstar = rotl(seed[0] * 5, 7) * 9; + t = seed[1] << 9; seed[2] ^= seed[0]; seed[3] ^= seed[1];