From 3155d31e12b4301cce738ceeaebe8fc8b3aba282 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Fri, 6 Dec 2024 08:46:34 +1300
Subject: [PATCH 2/4] 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 was reading 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.
---
 src/bin/pgbench/pgbench.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index c4c38099c5b..d1a802c5e6b 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -6611,27 +6611,23 @@ set_random_seed(const char *seed)
 	}
 	else
 	{
-		/* parse unsigned-int seed value */
-		unsigned long ulseed;
 		char		garbage;
 
-		/* Don't try to use UINT64_FORMAT here; it might not work for sscanf */
-		if (sscanf(seed, "%lu%c", &ulseed, &garbage) != 1)
+		if (sscanf(seed, "%" SCNu64 "%c", &iseed, &garbage) != 1)
 		{
 			pg_log_error("unrecognized random seed option \"%s\"", seed);
 			pg_log_error_detail("Expecting an unsigned integer, \"time\" or \"rand\".");
 			return false;
 		}
-		iseed = (uint64) ulseed;
 	}
 
 	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;
 
 	/* Initialize base_random_sequence using seed */
-	pg_prng_seed(&base_random_sequence, (uint64) iseed);
+	pg_prng_seed(&base_random_sequence, iseed);
 
 	return true;
 }
-- 
2.39.5

