Skip to content

Commit 53a2a15

Browse files
committed
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
1 parent d70b176 commit 53a2a15

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6634,27 +6634,23 @@ set_random_seed(const char *seed)
66346634
}
66356635
else
66366636
{
6637-
/* parse unsigned-int seed value */
6638-
unsigned long ulseed;
66396637
char garbage;
66406638

6641-
/* Don't try to use UINT64_FORMAT here; it might not work for sscanf */
6642-
if (sscanf(seed, "%lu%c", &ulseed, &garbage) != 1)
6639+
if (sscanf(seed, "%" SCNu64 "%c", &iseed, &garbage) != 1)
66436640
{
66446641
pg_log_error("unrecognized random seed option \"%s\"", seed);
66456642
pg_log_error_detail("Expecting an unsigned integer, \"time\" or \"rand\".");
66466643
return false;
66476644
}
6648-
iseed = (uint64) ulseed;
66496645
}
66506646

66516647
if (seed != NULL)
6652-
pg_log_info("setting random seed to %llu", (unsigned long long) iseed);
6648+
pg_log_info("setting random seed to %" PRIu64, iseed);
66536649

66546650
random_seed = iseed;
66556651

66566652
/* Initialize base_random_sequence using seed */
6657-
pg_prng_seed(&base_random_sequence, (uint64) iseed);
6653+
pg_prng_seed(&base_random_sequence, iseed);
66586654

66596655
return true;
66606656
}

0 commit comments

Comments
 (0)