From 866e76a178234f34799ec706e26c43cb19d3460f Mon Sep 17 00:00:00 2001
From: John Hsu <johnhyvr@gmail.com>
Date: Fri, 22 Dec 2023 22:38:15 +0000
Subject: [PATCH] Fix pgbench init overflow when total number of rows is
 greater than int32

Previously when the number of rows exceeds int32, it would
result in overflow and pgbench never finishing. This
change moves towards int64 to align with the comparison.
---
 src/bin/pgbench/pgbench.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 2e1650d0ad..dbdb486b40 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -4907,8 +4907,8 @@ static void
 initPopulateTable(PGconn *con, const char *table, int64 base,
 				  initRowMethod init_row)
 {
-	int			n;
-	int			k;
+	int64			n;
+	int64			k;
 	int			chars = 0;
 	PGresult   *res;
 	PQExpBufferData sql;
@@ -4938,7 +4938,7 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
 
 	n = pg_snprintf(copy_statement, sizeof(copy_statement), copy_statement_fmt, table);
 	if (n >= sizeof(copy_statement))
-		pg_fatal("invalid buffer size: must be at least %d characters long", n);
+		pg_fatal("invalid buffer size: must be at least " INT64_FORMAT " characters long", n);
 	else if (n == -1)
 		pg_fatal("invalid format string");
 
-- 
2.39.3

