From 4e997fcf86d0f454371f9efe17e20d5741e2daf9 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Fri, 6 Dec 2024 09:09:53 +1300
Subject: [PATCH 3/4] pgbench: Rationalize types in parseScriptWeight().

This function wanted to parse a 64 bit number, but complain if it was
out of range for int, and then include the number in the error message.
OK, but long is not always bigger than int, so it won't work the same on
all systems (and the cast to long long in the error message won't really
make it longer).

Parse with strtoi64(), and print it out with PRId64, so now it will
behave the same everywhere.
---
 src/bin/pgbench/pgbench.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index d1a802c5e6b..d4736fe5117 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -6173,7 +6173,7 @@ parseScriptWeight(const char *option, char **script)
 	if ((sep = strrchr(option, WSEP)))
 	{
 		int			namelen = sep - option;
-		long		wtmp;
+		int64		wtmp;
 		char	   *badp;
 
 		/* generate the script name */
@@ -6183,12 +6183,12 @@ parseScriptWeight(const char *option, char **script)
 
 		/* process digits of the weight spec */
 		errno = 0;
-		wtmp = strtol(sep + 1, &badp, 10);
+		wtmp = strtoi64(sep + 1, &badp, 10);
 		if (errno != 0 || badp == sep + 1 || *badp != '\0')
 			pg_fatal("invalid weight specification: %s", sep);
 		if (wtmp > INT_MAX || wtmp < 0)
-			pg_fatal("weight specification out of range (0 .. %d): %lld",
-					 INT_MAX, (long long) wtmp);
+			pg_fatal("weight specification out of range (0 .. %d): %" PRId64,
+					 INT_MAX, wtmp);
 		weight = wtmp;
 	}
 	else
-- 
2.39.5

