From: Paul Floyd Date: Thu, 17 Jul 2025 18:38:54 +0000 (+0200) Subject: iropt regtest: use mrand32() instead of rand() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c322bf33df88d1e8813434f7beeba909831a6a79;p=thirdparty%2Fvalgrind.git iropt regtest: use mrand32() instead of rand() On illumos rand() has a RAND_MAX of 32k only. That's not enough to generate 64bit values easily. So use mrand48() which genrerates the full range of 32bit int values. --- diff --git a/none/tests/iropt-test/main.c b/none/tests/iropt-test/main.c index 2622515e5..9f1cc5083 100644 --- a/none/tests/iropt-test/main.c +++ b/none/tests/iropt-test/main.c @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) { assert(sizeof(long long) == 8); - assert(RAND_MAX == INT32_MAX); + srand48(42L); for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "-v") == 0) diff --git a/none/tests/iropt-test/util.c b/none/tests/iropt-test/util.c index 072ff90c3..18b671114 100644 --- a/none/tests/iropt-test/util.c +++ b/none/tests/iropt-test/util.c @@ -109,7 +109,7 @@ bitsof_irtype(IRType ty) uint64_t get_random_value(IRType type) { - uint64_t val = rand(); + uint64_t val = mrand48(); switch (type) { case Ity_I1: return val & 0x1; @@ -117,11 +117,8 @@ get_random_value(IRType type) case Ity_I16: return val & UINT16_MAX; case Ity_I32: return val & UINT32_MAX; case Ity_I64: - /* Note, that RAND_MAX == INT32_MAX. Therefore, simply concatenating - two rand() values would never produce a value with MSB == 1 */ - val <<= (32 + 1); - val |= rand() << 1; - val |= rand() & 0x1; + val <<= 32; + val |= mrand48(); return val; default: