At Fri, 15 Mar 2024 16:01:28 +1300, David Rowley <dgrowle...@gmail.com> wrote 
in 
> On Fri, 15 Mar 2024 at 15:27, Kyotaro Horiguchi <horikyota....@gmail.com> 
> wrote:
> > I have considered only the two messages. Actually, buffile.c and md.c
> > are already like that. The attached aligns the messages in
> > pg_combinebackup.c and reconstruct.c with the precedents.
> 
> This looks like a worthy cause to make translator work easier.
> 
> I don't want to widen the goalposts or anything, but just wondering if
> you'd searched for any others that could get similar treatment?
> 
> I only just had a quick look at the following.
> 
> $ cat src/backend/po/fr.po | grep -E "^msgid\s" | sed -E
> 's/%[a-zA-Z]+/\%/g' | sort | uniq -d -c
>      31 msgid ""
>       2 msgid "could not accept SSL connection: %"
>       2 msgid "could not initialize LDAP: %"
>       2 msgid "could not look up local user ID %: %"
...
> I've not looked at how hard it would be with any of the above to
> determine how hard it would be to make the formats consistent.  The
> 3rd last one seems similar enough that it might be worth doing
> together with this?


I checked for that kind of msgids in a bit more intensive way. The
numbers are the line numbers in ja.po of backend. I didn't check the
same for other modules.

> ###: invalid timeline %lld
>        @ backup/walsummaryfuncs.c:95
>      invalid timeline %u
>        @ repl_gram.y:318 repl_gram.y:359

In the first case, the %lld can be more than 2^31.

In the second case, %u is uint32. However, the bigger issue is
checking if the uint32 value is negative:

repl_gram.c: 147
>       if ((yyvsp[0].uintval) <= 0)
>               ereport(ERROR,
>                               (errcode(ERRCODE_SYNTAX_ERROR),
>                                errmsg("invalid timeline %u", 
> (yyvsp[0].uintval))));

which cannot happen. I think we can simply remove the useless error
check.

> ###: could not read file \"%s\": read %d of %zu
>        @ ../common/controldata_utils.c:116 ../common/controldata_utils.c:119 
> access/transam/xlog.c:3417 access/transam/xlog.c:4278 
> replication/logical/origin.c:750 replication/logical/origin.c:789 
> replication/logical/snapbuild.c:2040 replication/slot.c:2218 
> replication/slot.c:2259 replication/walsender.c:660 
> utils/cache/relmapper.c:833
>      could not read file \"%s\": read %d of %lld
>        @ access/transam/twophase.c:1372
>      could not read file \"%s\": read %zd of %zu
>        @ backup/basebackup.c:2102
> ###: oversize GSSAPI packet sent by the client (%zu > %zu)
>        @ libpq/be-secure-gssapi.c:351
>      oversize GSSAPI packet sent by the client (%zu > %d)
>        @ libpq/be-secure-gssapi.c:575
> ###: compressed segment file \"%s\" has incorrect uncompressed size %d, 
> skipping
>        @ pg_receivewal.c:362
>      compressed segment file \"%s\" has incorrect uncompressed size %zu, 
> skipping
>        @ pg_receivewal.c:448
> ###: could not read file \"%s\": read only %zd of %lld bytes
>        @ pg_combinebackup.c:1304
>      could not read file \"%s\": read only %d of %u bytes
>        @ reconstruct.c:514


We can "fix" them the same way.  I debated whether to use ssize_t for
read() and replace all instances of size_t with Size. However, in the
end, I decided to only keep it consistent with the surrounding code.

> ###: index %d out of valid range, 0..%d
>        @ utils/adt/varlena.c:3220 utils/adt/varlena.c:3287
>      index %lld out of valid range, 0..%lld
>        @ utils/adt/varlena.c:3251 utils/adt/varlena.c:3323
> ###: string is too long for tsvector (%d bytes, max %d bytes)
>        @ tsearch/to_tsany.c:194 utils/adt/tsvector.c:277 
> utils/adt/tsvector_op.c:1126
>      string is too long for tsvector (%ld bytes, max %ld bytes)
>        @ utils/adt/tsvector.c:223

We can unify them and did in the attached, but I'm not sure that's
sensible..

> ###: could not look up local user ID %d: %s
>        @ ../port/user.c:43 ../port/user.c:79
>      could not look up local user ID %ld: %s
>        @ libpq/auth.c:1886

Both of the above use uid_t (defined as int) as user ID and it is
explicitly cast to "int" in the first case and to long in the second,
which seems mysterious. Although I'm not sure if there's a possibility
of uid_t being widened in the future, I unified them to the latter way
for robustness.

> ###: error while cloning relation \"%s.%s\" (\"%s\" to \"%s\"): %m
>        @ file.c:44
>      error while cloning relation \"%s.%s\" (\"%s\" to \"%s\"): %s
>        @ file.c:65
> 
> The latter seems to be changed to %m by reassiging save_errno to errno, as 
> done in other places.
> 
> ###: could not get data directory using %s: %m
>        @ option.c:448
>      could not get data directory using %s: %s
>        @ option.c:452
> ###: could not get control data using %s: %m
>        @ controldata.c:129 controldata.c:199
>      could not get control data using %s: %s
>        @ controldata.c:175 controldata.c:507
> ###: %s: %m
>        @ copy.c:401 psqlscanslash.l:805 psqlscanslash.l:817 
> psqlscanslash.l:835
>      %s: %s
>        @ command.c:2728 copy.c:388

In these cases, %m can be replaced by %s by using
wait_result_to_str(-1), but I'm not sure it is sensible. (I didn't do
that in the attached)

Finally, it doesn't seem possible to sensibly unify everything that
follows.

> ###: could not initialize LDAP: %s
>        @ libpq/auth.c:2327
>      could not initialize LDAP: %m
>        @ libpq/auth.c:2345
> ###: Valid values are between \"%d\" and \"%d\".
>        @ access/common/reloptions.c:1616
>      Valid values are between \"%f\" and \"%f\".
>        @ access/common/reloptions.c:1636
> ###: permission denied for large object %s
>        @ catalog/aclchk.c:2745
>      permission denied for large object %u
>        @ libpq/be-fsstubs.c:871 storage/large_object/inv_api.c:297 
> storage/large_object/inv_api.c:309 storage/large_object/inv_api.c:506 
> storage/large_object/inv_api.c:617 storage/large_object/inv_api.c:807
> ###: commutator operator %s is already the commutator of operator %s
>        @ catalog/pg_operator.c:739
>      commutator operator %s is already the commutator of operator %u
>        @ catalog/pg_operator.c:744
> ###: must be owner of large object %s
>        @ catalog/aclchk.c:2877
>      must be owner of large object %u
>        @ catalog/objectaddress.c:2511 libpq/be-fsstubs.c:329
> ###: could not open file \"%s\": %m
>        @ replication/slot.c:2186 replication/walsender.c:628 
> replication/walsender.c:3051 storage/file/copydir.c:151 storage/file/fd.c:803 
> storage/file/fd.c:3510 storage/file/fd.c:3740 storage/file/fd.c:3830 
> storage/smgr/md.c:661 utils/cache/relmapper.c:818 utils/cache/relmapper.c:935 
> utils/error/elog.c:2085 utils/init/miscinit.c:1526 utils/init/miscinit.c:1660 
> utils/init/miscinit.c:1737 utils/misc/guc.c:4712 utils/misc/guc.c:4762
>      could not open file \"%s\": %s
>        @ ../port/open.c:115
> ###: %d%s%s is outside the valid range for parameter \"%s\" (%d .. %d)
>        @ utils/misc/guc.c:3179
>      %g%s%s is outside the valid range for parameter \"%s\" (%g .. %g)
>        @ utils/misc/guc.c:3215
> ###: could not accept SSL connection: %m
>        @ libpq/be-secure-openssl.c:503
>      could not accept SSL connection: %s
>        @ libpq/be-secure-openssl.c:546
> ###: invalid value for parameter \"%s\": %d
>        @ utils/adt/regexp.c:716 utils/adt/regexp.c:725 
> utils/adt/regexp.c:1082 utils/adt/regexp.c:1146 utils/adt/regexp.c:1155 
> utils/adt/regexp.c:1164 utils/adt/regexp.c:1173 utils/adt/regexp.c:1853 
> utils/adt/regexp.c:1862 utils/adt/regexp.c:1871 utils/misc/guc.c:6761 
> utils/misc/guc.c:6795
>      invalid value for parameter \"%s\": %g
>        @ utils/misc/guc.c:6829
> ###: could not close file \"%s\": %m
>        @ bbstreamer_file.c:138 pg_recvlogical.c:650
>      could not close file \"%s\": %s
>        @ receivelog.c:227 receivelog.c:317 receivelog.c:688
> ###: could not fsync file \"%s\": %m
>        @ pg_recvlogical.c:204
>      could not fsync file \"%s\": %s
>        @ receivelog.c:775 receivelog.c:1022 walmethods.c:1206
> ###: could not read from input file: %s
>        @ compress_lz4.c:628 compress_lz4.c:647 compress_none.c:97 
> compress_none.c:140
>      could not read from input file: %m
>        @ compress_zstd.c:373 pg_backup_custom.c:655
> ###: could not get pg_ctl version data using %s: %m
>        @ exec.c:47
>      could not get pg_ctl version data using %s: %s
>        @ exec.c:51
> ###: negator operator %s is already the negator of operator %s
>        @ catalog/pg_operator.c:807
>      negator operator %s is already the negator of operator %u
>        @ catalog/pg_operator.c:812
> ###: timestamp out of range: \"%s\"
>        @ access/transam/xlogrecovery.c:4937 utils/adt/timestamp.c:202 
> utils/adt/timestamp.c:455
>      timestamp out of range: \"%g\"
>        @ utils/adt/timestamp.c:762 utils/adt/timestamp.c:774

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 8090ac9fc1..12515e7af2 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -1310,7 +1310,7 @@ ReadTwoPhaseFile(TransactionId xid, bool missing_ok)
 	uint32		crc_offset;
 	pg_crc32c	calc_crc,
 				file_crc;
-	int			r;
+	ssize_t		r;
 
 	TwoPhaseFilePath(path, xid);
 
@@ -1369,8 +1369,8 @@ ReadTwoPhaseFile(TransactionId xid, bool missing_ok)
 					 errmsg("could not read file \"%s\": %m", path)));
 		else
 			ereport(ERROR,
-					(errmsg("could not read file \"%s\": read %d of %lld",
-							path, r, (long long int) stat.st_size)));
+					(errmsg("could not read file \"%s\": read %zd of %zu",
+							path, r, (Size) stat.st_size)));
 	}
 
 	pgstat_report_wait_end();
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 20a5f86209..3331f23f69 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -3385,7 +3385,7 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno,
 	 */
 	for (nbytes = 0; nbytes < wal_segment_size; nbytes += sizeof(buffer))
 	{
-		int			nread;
+		ssize_t		nread;
 
 		nread = upto - nbytes;
 
@@ -3398,7 +3398,7 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno,
 
 		if (nread > 0)
 		{
-			int			r;
+			ssize_t		r;
 
 			if (nread > sizeof(buffer))
 				nread = sizeof(buffer);
@@ -3414,7 +3414,7 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno,
 				else
 					ereport(ERROR,
 							(errcode(ERRCODE_DATA_CORRUPTED),
-							 errmsg("could not read file \"%s\": read %d of %zu",
+							 errmsg("could not read file \"%s\": read %zd of %zu",
 									path, r, (Size) nread)));
 			}
 			pgstat_report_wait_end();
@@ -4250,7 +4250,7 @@ ReadControlFile(void)
 	pg_crc32c	crc;
 	int			fd;
 	static char wal_segsz_str[20];
-	int			r;
+	ssize_t		r;
 
 	/*
 	 * Read data...
@@ -4275,7 +4275,7 @@ ReadControlFile(void)
 		else
 			ereport(PANIC,
 					(errcode(ERRCODE_DATA_CORRUPTED),
-					 errmsg("could not read file \"%s\": read %d of %zu",
+					 errmsg("could not read file \"%s\": read %zd of %zu",
 							XLOG_CONTROL_FILE, r, sizeof(ControlFileData))));
 	}
 	pgstat_report_wait_end();
diff --git a/src/backend/libpq/be-secure-gssapi.c b/src/backend/libpq/be-secure-gssapi.c
index bc04e78abb..68645b4519 100644
--- a/src/backend/libpq/be-secure-gssapi.c
+++ b/src/backend/libpq/be-secure-gssapi.c
@@ -572,9 +572,9 @@ secure_open_gssapi(Port *port)
 		if (input.length > PQ_GSS_RECV_BUFFER_SIZE)
 		{
 			ereport(COMMERROR,
-					(errmsg("oversize GSSAPI packet sent by the client (%zu > %d)",
+					(errmsg("oversize GSSAPI packet sent by the client (%zu > %zu)",
 							(size_t) input.length,
-							PQ_GSS_RECV_BUFFER_SIZE)));
+							(size_t) PQ_GSS_RECV_BUFFER_SIZE)));
 			return -1;
 		}
 
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index a529da983a..f56f704aee 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -700,7 +700,7 @@ StartupReplicationOrigin(void)
 {
 	const char *path = "pg_logical/replorigin_checkpoint";
 	int			fd;
-	int			readBytes;
+	ssize_t		readBytes;
 	uint32		magic = REPLICATION_STATE_MAGIC;
 	int			last_state = 0;
 	pg_crc32c	file_crc;
@@ -747,7 +747,7 @@ StartupReplicationOrigin(void)
 		else
 			ereport(PANIC,
 					(errcode(ERRCODE_DATA_CORRUPTED),
-					 errmsg("could not read file \"%s\": read %d of %zu",
+					 errmsg("could not read file \"%s\": read %zd of %zu",
 							path, readBytes, sizeof(magic))));
 	}
 	COMP_CRC32C(crc, &magic, sizeof(magic));
@@ -786,7 +786,7 @@ StartupReplicationOrigin(void)
 		{
 			ereport(PANIC,
 					(errcode_for_file_access(),
-					 errmsg("could not read file \"%s\": read %d of %zu",
+					 errmsg("could not read file \"%s\": read %zd of %zu",
 							path, readBytes, sizeof(disk_state))));
 		}
 
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index ac24b51860..729b80385a 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -2016,7 +2016,7 @@ snapshot_not_interesting:
 static void
 SnapBuildRestoreContents(int fd, char *dest, Size size, const char *path)
 {
-	int			readBytes;
+	ssize_t		readBytes;
 
 	pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_READ);
 	readBytes = read(fd, dest, size);
@@ -2037,7 +2037,7 @@ SnapBuildRestoreContents(int fd, char *dest, Size size, const char *path)
 		else
 			ereport(ERROR,
 					(errcode(ERRCODE_DATA_CORRUPTED),
-					 errmsg("could not read file \"%s\": read %d of %zu",
+					 errmsg("could not read file \"%s\": read %zd of %zu",
 							path, readBytes, size)));
 	}
 }
diff --git a/src/backend/replication/repl_gram.y b/src/backend/replication/repl_gram.y
index 7474f5bd67..baa76280b9 100644
--- a/src/backend/replication/repl_gram.y
+++ b/src/backend/replication/repl_gram.y
@@ -312,11 +312,6 @@ timeline_history:
 				{
 					TimeLineHistoryCmd *cmd;
 
-					if ($2 <= 0)
-						ereport(ERROR,
-								(errcode(ERRCODE_SYNTAX_ERROR),
-								 errmsg("invalid timeline %u", $2)));
-
 					cmd = makeNode(TimeLineHistoryCmd);
 					cmd->timeline = $2;
 
@@ -352,13 +347,7 @@ opt_slot:
 
 opt_timeline:
 			K_TIMELINE UCONST
-				{
-					if ($2 <= 0)
-						ereport(ERROR,
-								(errcode(ERRCODE_SYNTAX_ERROR),
-								 errmsg("invalid timeline %u", $2)));
-					$$ = $2;
-				}
+				{ $$ = $2; }
 				| /* EMPTY */			{ $$ = 0; }
 			;
 
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index 91ca397857..09422a1f7d 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -2156,7 +2156,7 @@ RestoreSlotFromDisk(const char *name)
 	char		path[MAXPGPATH + 22];
 	int			fd;
 	bool		restored = false;
-	int			readBytes;
+	ssize_t		readBytes;
 	pg_crc32c	checksum;
 
 	/* no need to lock here, no concurrent access allowed yet */
@@ -2215,7 +2215,7 @@ RestoreSlotFromDisk(const char *name)
 		else
 			ereport(PANIC,
 					(errcode(ERRCODE_DATA_CORRUPTED),
-					 errmsg("could not read file \"%s\": read %d of %zu",
+					 errmsg("could not read file \"%s\": read %zd of %zu",
 							path, readBytes,
 							(Size) ReplicationSlotOnDiskConstantSize)));
 	}
@@ -2256,7 +2256,7 @@ RestoreSlotFromDisk(const char *name)
 		else
 			ereport(PANIC,
 					(errcode(ERRCODE_DATA_CORRUPTED),
-					 errmsg("could not read file \"%s\": read %d of %zu",
+					 errmsg("could not read file \"%s\": read %zd of %zu",
 							path, readBytes, (Size) cp.length)));
 	}
 
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index bc40c454de..706903b9fa 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -644,7 +644,7 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
 	while (bytesleft > 0)
 	{
 		PGAlignedBlock rbuf;
-		int			nread;
+		ssize_t		   nread;
 
 		pgstat_report_wait_start(WAIT_EVENT_WALSENDER_TIMELINE_HISTORY_READ);
 		nread = read(fd, rbuf.data, sizeof(rbuf));
@@ -657,7 +657,7 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
 		else if (nread == 0)
 			ereport(ERROR,
 					(errcode(ERRCODE_DATA_CORRUPTED),
-					 errmsg("could not read file \"%s\": read %d of %zu",
+					 errmsg("could not read file \"%s\": read %zd of %zu",
 							path, nread, (Size) bytesleft)));
 
 		pq_sendbytes(&buf, rbuf.data, nread);
diff --git a/src/backend/tsearch/to_tsany.c b/src/backend/tsearch/to_tsany.c
index 88cba58cba..9d21178107 100644
--- a/src/backend/tsearch/to_tsany.c
+++ b/src/backend/tsearch/to_tsany.c
@@ -191,7 +191,8 @@ make_tsvector(ParsedText *prs)
 	if (lenstr > MAXSTRPOS)
 		ereport(ERROR,
 				(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
-				 errmsg("string is too long for tsvector (%d bytes, max %d bytes)", lenstr, MAXSTRPOS)));
+				 /* cast values to avoid extra translatable messages */
+				 errmsg("string is too long for tsvector (%ld bytes, max %ld bytes)", (long) lenstr, (long) MAXSTRPOS)));
 
 	totallen = CALCDATASIZE(prs->curwords, lenstr);
 	in = (TSVector) palloc0(totallen);
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 8d28dd42ce..5de490b569 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -3217,8 +3217,9 @@ byteaGetByte(PG_FUNCTION_ARGS)
 	if (n < 0 || n >= len)
 		ereport(ERROR,
 				(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
-				 errmsg("index %d out of valid range, 0..%d",
-						n, len - 1)));
+				 /* cast values to avoid extra translable messages */
+				 errmsg("index %lld out of valid range, 0..%lld",
+						(long long)n, (long long) len - 1)));
 
 	byte = ((unsigned char *) VARDATA_ANY(v))[n];
 
diff --git a/src/backend/utils/cache/relmapper.c b/src/backend/utils/cache/relmapper.c
index 48d344ae3f..6d118a1da7 100644
--- a/src/backend/utils/cache/relmapper.c
+++ b/src/backend/utils/cache/relmapper.c
@@ -786,7 +786,7 @@ read_relmap_file(RelMapFile *map, char *dbpath, bool lock_held, int elevel)
 	char		mapfilename[MAXPGPATH];
 	pg_crc32c	crc;
 	int			fd;
-	int			r;
+	ssize_t		r;
 
 	Assert(elevel >= ERROR);
 
@@ -830,7 +830,7 @@ read_relmap_file(RelMapFile *map, char *dbpath, bool lock_held, int elevel)
 		else
 			ereport(elevel,
 					(errcode(ERRCODE_DATA_CORRUPTED),
-					 errmsg("could not read file \"%s\": read %d of %zu",
+					 errmsg("could not read file \"%s\": read %zd of %zu",
 							mapfilename, r, sizeof(RelMapFile))));
 	}
 	pgstat_report_wait_end();
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index 555f0175f0..c1430e7950 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -329,9 +329,9 @@ FindStreamingStart(uint32 *tli)
 		{
 			int			fd;
 			char		buf[4];
-			int			bytes_out;
+			size_t		bytes_out;
 			char		fullpath[MAXPGPATH * 2];
-			int			r;
+			ssize_t		r;
 
 			snprintf(fullpath, sizeof(fullpath), "%s/%s", basedir, dirent->d_name);
 
@@ -349,7 +349,7 @@ FindStreamingStart(uint32 *tli)
 					pg_fatal("could not read compressed file \"%s\": %m",
 							 fullpath);
 				else
-					pg_fatal("could not read compressed file \"%s\": read %d of %zu",
+					pg_fatal("could not read compressed file \"%s\": read %zd of %zu",
 							 fullpath, r, sizeof(buf));
 			}
 
@@ -359,7 +359,7 @@ FindStreamingStart(uint32 *tli)
 
 			if (bytes_out != WalSegSz)
 			{
-				pg_log_warning("compressed segment file \"%s\" has incorrect uncompressed size %d, skipping",
+				pg_log_warning("compressed segment file \"%s\" has incorrect uncompressed size %zu, skipping",
 							   dirent->d_name, bytes_out);
 				continue;
 			}
diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c
index 6f0814d9ac..feb4d5dcf4 100644
--- a/src/bin/pg_combinebackup/pg_combinebackup.c
+++ b/src/bin/pg_combinebackup/pg_combinebackup.c
@@ -1301,8 +1301,9 @@ slurp_file(int fd, char *filename, StringInfo buf, int maxlen)
 		if (rb < 0)
 			pg_fatal("could not read file \"%s\": %m", filename);
 		else
-			pg_fatal("could not read file \"%s\": read only %zd of %lld bytes",
-					 filename, rb, (long long int) st.st_size);
+			/* cast st_size to avoid extra translatable messages */
+			pg_fatal("could not read file \"%s\": read only %zd of %zu bytes",
+					 filename, rb, (size_t) st.st_size);
 	}
 
 	/* Adjust buffer length for new data and restore trailing-\0 invariant */
diff --git a/src/bin/pg_combinebackup/reconstruct.c b/src/bin/pg_combinebackup/reconstruct.c
index 41f06bb26b..a4badb90e2 100644
--- a/src/bin/pg_combinebackup/reconstruct.c
+++ b/src/bin/pg_combinebackup/reconstruct.c
@@ -504,15 +504,16 @@ make_rfile(char *filename, bool missing_ok)
 static void
 read_bytes(rfile *rf, void *buffer, unsigned length)
 {
-	int			rb = read(rf->fd, buffer, length);
+	ssize_t		rb = read(rf->fd, buffer, length);
 
 	if (rb != length)
 	{
 		if (rb < 0)
 			pg_fatal("could not read file \"%s\": %m", rf->filename);
 		else
-			pg_fatal("could not read file \"%s\": read only %d of %u bytes",
-					 rf->filename, rb, length);
+			/* cast length to avoid extra translatable messages */
+			pg_fatal("could not read file \"%s\": read only %zd of %zu bytes",
+					 rf->filename, rb, (size_t) length);
 	}
 }
 
diff --git a/src/bin/pg_upgrade/file.c b/src/bin/pg_upgrade/file.c
index 73932504ca..82713534c0 100644
--- a/src/bin/pg_upgrade/file.c
+++ b/src/bin/pg_upgrade/file.c
@@ -62,8 +62,9 @@ cloneFile(const char *src, const char *dst,
 
 		unlink(dst);
 
-		pg_fatal("error while cloning relation \"%s.%s\" (\"%s\" to \"%s\"): %s",
-				 schemaName, relName, src, dst, strerror(save_errno));
+		errno = save_errno;
+		pg_fatal("error while cloning relation \"%s.%s\" (\"%s\" to \"%s\"): %m",
+				 schemaName, relName, src, dst);
 	}
 
 	close(src_fd);
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 82309b2510..dfa5fa8c08 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -70,7 +70,7 @@ get_controlfile_by_exact_path(const char *ControlFilePath, bool *crc_ok_p)
 	ControlFileData *ControlFile;
 	int			fd;
 	pg_crc32c	crc;
-	int			r;
+	ssize_t		r;
 #ifdef FRONTEND
 	pg_crc32c	last_crc;
 	int			retries = 0;
@@ -113,10 +113,10 @@ retry:
 #ifndef FRONTEND
 			ereport(ERROR,
 					(errcode(ERRCODE_DATA_CORRUPTED),
-					 errmsg("could not read file \"%s\": read %d of %zu",
+					 errmsg("could not read file \"%s\": read %zd of %zu",
 							ControlFilePath, r, sizeof(ControlFileData))));
 #else
-			pg_fatal("could not read file \"%s\": read %d of %zu",
+			pg_fatal("could not read file \"%s\": read %zd of %zu",
 					 ControlFilePath, r, sizeof(ControlFileData));
 #endif
 	}
diff --git a/src/port/user.c b/src/port/user.c
index 7444aeb64b..9364bdb69e 100644
--- a/src/port/user.c
+++ b/src/port/user.c
@@ -40,8 +40,8 @@ pg_get_user_name(uid_t user_id, char *buffer, size_t buflen)
 	}
 	if (pwerr != 0)
 		snprintf(buffer, buflen,
-				 _("could not look up local user ID %d: %s"),
-				 (int) user_id,
+				 _("could not look up local user ID %ld: %s"),
+				 (long) user_id,
 				 strerror_r(pwerr, pwdbuf, sizeof(pwdbuf)));
 	else
 		snprintf(buffer, buflen,
@@ -76,13 +76,13 @@ pg_get_user_home_dir(uid_t user_id, char *buffer, size_t buflen)
 	}
 	if (pwerr != 0)
 		snprintf(buffer, buflen,
-				 _("could not look up local user ID %d: %s"),
-				 (int) user_id,
+				 _("could not look up local user ID %ld: %s"),
+				 (long) user_id,
 				 strerror_r(pwerr, pwdbuf, sizeof(pwdbuf)));
 	else
 		snprintf(buffer, buflen,
-				 _("local user with ID %d does not exist"),
-				 (int) user_id);
+				 _("local user with ID %ld does not exist"),
+				 (long) user_id);
 	return false;
 }
 

Reply via email to