Template
1
0
mirror of https://github.com/bol-van/zapret2.git synced 2026-03-13 22:03:09 +00:00

nfqws2: fix sz=0 case in fill_random_bytes

This commit is contained in:
bol-van
2026-02-06 14:58:24 +03:00
parent 8a5643851d
commit 392e1cc1ef

View File

@@ -456,11 +456,14 @@ bool file_open_test(const char *filename, int flags)
void fill_random_bytes(uint8_t *p,size_t sz)
{
size_t k;
// alignment
if ((size_t)p & 1) { *p=(uint8_t)random(); sz--; p++; }
// random has only 31 bits of entropy. not 32 bits
for (k=0 ; (k+1)<sz ; k+=2) *(uint16_t*)(p+k) = (uint16_t)random();
if (sz & 1) p[sz-1]=(uint8_t)random();
if (sz)
{
// alignment
if ((size_t)p & 1) { *p=(uint8_t)random(); sz--; p++; }
// random has only 31 bits of entropy. not 32 bits
for (k=0 ; (k+1)<sz ; k+=2) *(uint16_t*)(p+k) = (uint16_t)random();
if (sz & 1) p[sz-1]=(uint8_t)random();
}
}
void fill_random_az(uint8_t *p,size_t sz)
{