From abc484db5e5f079e128b6bf4aeaa11bf1abdaaf9 Mon Sep 17 00:00:00 2001 From: wuyihung Date: Sun, 17 Mar 2024 13:37:57 +0800 Subject: [PATCH] Improve fill_rand_string --- qtest.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/qtest.c b/qtest.c index 0de4842ce..7b21bcfb5 100644 --- a/qtest.c +++ b/qtest.c @@ -172,9 +172,12 @@ static void fill_rand_string(char *buf, size_t buf_size) while (len < MIN_RANDSTR_LEN) len = rand() % buf_size; - randombytes((uint8_t *) buf, len); + uint64_t *randstr_buf_64 = malloc(len * sizeof(uint64_t)); + randombytes((uint8_t *) randstr_buf_64, len * sizeof(uint64_t)); for (size_t n = 0; n < len; n++) - buf[n] = charset[buf[n] % (sizeof(charset) - 1)]; + buf[n] = charset[randstr_buf_64[n] % (sizeof(charset) - 1)]; + + free(randstr_buf_64); buf[len] = '\0'; }