mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
pgbench: Make set_random_seed() 64-bit everywhere.
Delete an intermediate variable, a redundant cast, a use of long and a use of long long. scanf() the seed directly into a uint64, now that we can do that with SCNu64 from <inttypes.h>. The previous coding was from pre-C99 times when %lld might not have been there, so it read into an unsigned long. Therefore behavior varied by OS, and --random-seed would accept either 32 or 64 bit seeds. Now it's the same everywhere. Author: Thomas Munro <thomas.munro@gmail.com> Discussion: https://postgr.es/m/b936d2fb-590d-49c3-a615-92c3a88c6c19%40eisentraut.org
This commit is contained in:
@ -6634,27 +6634,23 @@ set_random_seed(const char *seed)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* parse unsigned-int seed value */
|
|
||||||
unsigned long ulseed;
|
|
||||||
char garbage;
|
char garbage;
|
||||||
|
|
||||||
/* Don't try to use UINT64_FORMAT here; it might not work for sscanf */
|
if (sscanf(seed, "%" SCNu64 "%c", &iseed, &garbage) != 1)
|
||||||
if (sscanf(seed, "%lu%c", &ulseed, &garbage) != 1)
|
|
||||||
{
|
{
|
||||||
pg_log_error("unrecognized random seed option \"%s\"", seed);
|
pg_log_error("unrecognized random seed option \"%s\"", seed);
|
||||||
pg_log_error_detail("Expecting an unsigned integer, \"time\" or \"rand\".");
|
pg_log_error_detail("Expecting an unsigned integer, \"time\" or \"rand\".");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
iseed = (uint64) ulseed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seed != NULL)
|
if (seed != NULL)
|
||||||
pg_log_info("setting random seed to %llu", (unsigned long long) iseed);
|
pg_log_info("setting random seed to %" PRIu64, iseed);
|
||||||
|
|
||||||
random_seed = iseed;
|
random_seed = iseed;
|
||||||
|
|
||||||
/* Initialize base_random_sequence using seed */
|
/* Initialize base_random_sequence using seed */
|
||||||
pg_prng_seed(&base_random_sequence, (uint64) iseed);
|
pg_prng_seed(&base_random_sequence, iseed);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user