Fix OAI_RNGSEED to capture unsigned long

atoi() used previously does not capture all of unsigned long (so we
could not reproduce a high seed), and its use is discouraged as it does
not detect errors. Use strtoul() instead, which allows to also use other
bases (so we can e.g., write OAI_RNGSEED=0x1234)
This commit is contained in:
Robert Schmidt
2025-12-01 12:10:31 +01:00
parent a1b4220a91
commit ce7cb165dd
+8 -1
View File
@@ -56,7 +56,14 @@ void randominit()
unsigned long seed;
const char* str_oai_rngseed = getenv("OAI_RNGSEED");
if (str_oai_rngseed != NULL) {
seed = atoi(str_oai_rngseed);
char *end;
seed = strtoul(str_oai_rngseed, &end, 0); /* 0: any base in hex, dec, oct */
AssertFatal(*end == '\0' || *end == '\n',
"could not read seed %s at char '%c' (%d), pos %ld\n",
str_oai_rngseed,
*end,
*end,
end - str_oai_rngseed);
} else {
fill_random(&seed, sizeof(seed));
}