memcpy(x, NULL, 0) is undefined behavior

This commit is contained in:
TuxSH 2018-03-08 11:17:46 +01:00
parent 3d8ff446ad
commit b35c418558
7 changed files with 31 additions and 13 deletions

View file

@ -61,13 +61,15 @@ void randomcache_refill(void) {
void randomcache_getbytes(void *dst, size_t num_bytes) {
unsigned int low = g_random_cache_low;
if (num_bytes == 0) {
return;
}
memcpy(dst, &g_random_cache[low], num_bytes);
unsigned int new_low = low + num_bytes;
if (new_low + 0x38 > 0x3FF) {
new_low = 0;
}
g_random_cache_low = new_low;
}