From: Habu Date: Sat, 8 Mar 2014 13:04:39 +0000 (+0900) Subject: Initialize Rand_state directly insted of using temporary buffer X-Git-Tag: v2.2.0~276 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=f222ea9d1e09bcecad16a312e822688d3120307d;p=hengbandforosx%2Fhengbandosx.git Initialize Rand_state directly insted of using temporary buffer --- diff --git a/src/z-rand.c b/src/z-rand.c index 699e1fa1b..af939f6c4 100644 --- a/src/z-rand.c +++ b/src/z-rand.c @@ -115,23 +115,22 @@ void Rand_state_init(void) #ifdef RNG_DEVICE FILE *fp = fopen(RNG_DEVICE, "r"); - u32b buf[4]; + do { - fread(buf, sizeof(buf[0]), 4, fp); - } while ((buf[0] | buf[1] | buf[2] | buf[3]) == 0); - memcpy(Rand_state, buf, sizeof(buf)); + fread(Rand_state, sizeof(Rand_state[0]), 4, fp); + } while ((Rand_state[0] | Rand_state[1] | Rand_state[2] | Rand_state[3]) == 0); + fclose(fp); #elif defined(WINDOWS) HCRYPTPROV hProvider; - u32b buf[4]; CryptAcquireContext(&hProvider, NULL, NULL, PROV_RSA_FULL, 0); do { - CryptGenRandom(hProvider, sizeof(buf[0]) * 4, (BYTE*)buf); - } while ((buf[0] | buf[1] | buf[2] | buf[3]) == 0); + CryptGenRandom(hProvider, sizeof(Rand_state[0]) * 4, (BYTE*)Rand_state); + } while ((Rand_state[0] | Rand_state[1] | Rand_state[2] | Rand_state[3]) == 0); CryptReleaseContext(hProvider, 0);