0002-Clean-up-int64-related-format-strings.patch

text/plain

Filename: 0002-Clean-up-int64-related-format-strings.patch
Type: text/plain
Part: 1
Message: Remove unnecessary casts in printf format arguments

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch 0002
Subject: Clean up int64-related format strings
File+
contrib/isn/isn.c 4 22
contrib/isn/isn.h 0 2
contrib/pageinspect/btreefuncs.c 5 6
src/backend/backup/basebackup.c 2 2
src/bin/pg_rewind/pg_rewind.c 3 3
From 3df7005b6fdd213273eeccbfecf7650b25012e6c Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Thu, 4 Dec 2025 12:58:05 +0100
Subject: [PATCH 2/3] Clean up int64-related format strings

Remove some gratuitous uses of INT64_FORMAT.  Make use of
PRIu64/PRId64 were appropriate, remove unnecessary casts.
---
 contrib/isn/isn.c                | 26 ++++----------------------
 contrib/isn/isn.h                |  2 --
 contrib/pageinspect/btreefuncs.c | 11 +++++------
 src/backend/backup/basebackup.c  |  4 ++--
 src/bin/pg_rewind/pg_rewind.c    |  6 +++---
 5 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/contrib/isn/isn.c b/contrib/isn/isn.c
index 1880c91844e..3caa3af8b4c 100644
--- a/contrib/isn/isn.c
+++ b/contrib/isn/isn.c
@@ -423,19 +423,10 @@ ean2isn(ean13 ean, bool errorOK, ean13 *result, enum isn_type accept)
 
 eantoobig:
 	if (!errorOK)
-	{
-		char		eanbuf[64];
-
-		/*
-		 * Format the number separately to keep the machine-dependent format
-		 * code out of the translatable message text
-		 */
-		snprintf(eanbuf, sizeof(eanbuf), EAN13_FORMAT, ean);
 		ereport(ERROR,
 				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
-				 errmsg("value \"%s\" is out of range for %s type",
-						eanbuf, isn_names[type])));
-	}
+				 errmsg("value \"%" PRIu64 "\" is out of range for %s type",
+						ean, isn_names[type])));
 	return false;
 }
 
@@ -660,19 +651,10 @@ ean2string(ean13 ean, bool errorOK, char *result, bool shortType)
 
 eantoobig:
 	if (!errorOK)
-	{
-		char		eanbuf[64];
-
-		/*
-		 * Format the number separately to keep the machine-dependent format
-		 * code out of the translatable message text
-		 */
-		snprintf(eanbuf, sizeof(eanbuf), EAN13_FORMAT, ean);
 		ereport(ERROR,
 				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
-				 errmsg("value \"%s\" is out of range for %s type",
-						eanbuf, isn_names[type])));
-	}
+				 errmsg("value \"%" PRIu64 "\" is out of range for %s type",
+						ean, isn_names[type])));
 	return false;
 }
 
diff --git a/contrib/isn/isn.h b/contrib/isn/isn.h
index 399896ad417..4551d7828fb 100644
--- a/contrib/isn/isn.h
+++ b/contrib/isn/isn.h
@@ -24,8 +24,6 @@
  */
 typedef uint64 ean13;
 
-#define EAN13_FORMAT UINT64_FORMAT
-
 #define PG_GETARG_EAN13(n) PG_GETARG_INT64(n)
 #define PG_RETURN_EAN13(x) PG_RETURN_INT64(x)
 
diff --git a/contrib/pageinspect/btreefuncs.c b/contrib/pageinspect/btreefuncs.c
index 2e67c9adf5a..0b95a376a36 100644
--- a/contrib/pageinspect/btreefuncs.c
+++ b/contrib/pageinspect/btreefuncs.c
@@ -901,10 +901,10 @@ bt_metap(PG_FUNCTION_ARGS)
 	j = 0;
 	values[j++] = psprintf("%d", metad->btm_magic);
 	values[j++] = psprintf("%d", metad->btm_version);
-	values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_root);
-	values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_level);
-	values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_fastroot);
-	values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_fastlevel);
+	values[j++] = psprintf("%u", metad->btm_root);
+	values[j++] = psprintf("%u", metad->btm_level);
+	values[j++] = psprintf("%u", metad->btm_fastroot);
+	values[j++] = psprintf("%u", metad->btm_fastlevel);
 
 	/*
 	 * Get values of extended metadata if available, use default values
@@ -914,8 +914,7 @@ bt_metap(PG_FUNCTION_ARGS)
 	 */
 	if (metad->btm_version >= BTREE_NOVAC_VERSION)
 	{
-		values[j++] = psprintf(INT64_FORMAT,
-							   (int64) metad->btm_last_cleanup_num_delpages);
+		values[j++] = psprintf("%u", metad->btm_last_cleanup_num_delpages);
 		values[j++] = psprintf("%f", metad->btm_last_cleanup_num_heap_tuples);
 		values[j++] = metad->btm_allequalimage ? "t" : "f";
 	}
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 2be4e069816..1fbc9af72ba 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -808,8 +808,8 @@ parse_basebackup_options(List *options, basebackup_options *opt)
 			if (maxrate < MAX_RATE_LOWER || maxrate > MAX_RATE_UPPER)
 				ereport(ERROR,
 						(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
-						 errmsg("%d is outside the valid range for parameter \"%s\" (%d .. %d)",
-								(int) maxrate, "MAX_RATE", MAX_RATE_LOWER, MAX_RATE_UPPER)));
+						 errmsg("%" PRId64 " is outside the valid range for parameter \"%s\" (%d .. %d)",
+								maxrate, "MAX_RATE", MAX_RATE_LOWER, MAX_RATE_UPPER)));
 
 			opt->maxrate = (uint32) maxrate;
 			o_maxrate = true;
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 7837e01d83d..06c464f6ac5 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -514,9 +514,9 @@ main(int argc, char **argv)
 	 */
 	if (showprogress)
 	{
-		pg_log_info("need to copy %lu MB (total source directory size is %lu MB)",
-					(unsigned long) (filemap->fetch_size / (1024 * 1024)),
-					(unsigned long) (filemap->total_size / (1024 * 1024)));
+		pg_log_info("need to copy %" PRIu64 " MB (total source directory size is %" PRIu64 " MB)",
+					filemap->fetch_size / (1024 * 1024),
+					filemap->total_size / (1024 * 1024));
 
 		fetch_size = filemap->fetch_size;
 		fetch_done = 0;
-- 
2.52.0