pgsql: Clean up read() return type

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Clean up read() return type
Date: 2026-07-15 07:50:07
Message-ID: E1wjuNa-000GNL-1Q@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Clean up read() return type

and analogously for pg_pread() and FileRead()

Be sure to store the return value in a variable of type ssize_t, not
int.

Also make the error messages for short reads consistent. They should
always be like "read %zd of %zu". Appearance of other placeholders
indicates the types are probably wrong (although in some cases some
casts are added to make macros have the right type and keep the
strings consistent, and it some cases it's left as "%zu of %zu", which
is close enough).

In several cases, the input length is derived from struct stat
st_size, which has type off_t, which is neither size_t nor ssize_t.
To keep the type handling clearer, this introduces intermediate
variables in these cases.

In SendTimeLineHistory() in walsender.c, we need to adjust the logic a
bit to over underflow wrap if we end up reading more from the file
than expected. This is believed to be a theoretical problem only.
Alternatively, we could treat this as an error. Note that the
previous code would have processed the extra data but only up to a
full block, which seems wrong in any case.

Reviewed-by: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Discussion: https://www.postgresql.org/message-id/flat/f9aab072-0078-49e4-ab93-3b08086a4406(at)eisentraut(dot)org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ca326e903df4b2efcc7b9090abc4d1a9c27c3088

Modified Files
--------------
contrib/basic_archive/basic_archive.c | 6 ++--
src/backend/access/transam/timeline.c | 8 +++---
src/backend/access/transam/twophase.c | 14 +++++----
src/backend/access/transam/xlog.c | 12 ++++----
src/backend/access/transam/xlogreader.c | 4 +--
src/backend/access/transam/xlogrecovery.c | 4 +--
src/backend/access/transam/xlogutils.c | 4 +--
src/backend/libpq/be-fsstubs.c | 4 +--
src/backend/postmaster/syslogger.c | 2 +-
src/backend/replication/logical/origin.c | 6 ++--
src/backend/replication/logical/reorderbuffer.c | 16 +++++------
src/backend/replication/logical/snapbuild.c | 4 +--
src/backend/replication/slot.c | 8 +++---
src/backend/replication/walsender.c | 18 +++++++++---
src/backend/storage/file/buffile.c | 15 ++++++----
src/backend/storage/file/copydir.c | 4 +--
src/backend/storage/ipc/waiteventset.c | 2 +-
src/backend/storage/smgr/md.c | 2 +-
src/backend/utils/cache/relmapper.c | 4 +--
src/backend/utils/init/miscinit.c | 7 +++--
src/backend/utils/probes.d | 2 +-
src/bin/pg_basebackup/pg_basebackup.c | 7 +++--
src/bin/pg_basebackup/pg_receivewal.c | 4 +--
src/bin/pg_checksums/pg_checksums.c | 7 +++--
src/bin/pg_combinebackup/load_manifest.c | 33 ++++++++++++---------
src/bin/pg_combinebackup/pg_combinebackup.c | 13 +++++----
src/bin/pg_combinebackup/reconstruct.c | 16 ++++++-----
src/bin/pg_ctl/pg_ctl.c | 16 ++++++-----
src/bin/pg_resetwal/pg_resetwal.c | 2 +-
src/bin/pg_rewind/file_ops.c | 8 +++---
src/bin/pg_rewind/parsexlog.c | 5 ++--
src/bin/pg_verifybackup/pg_verifybackup.c | 38 ++++++++++++++-----------
src/bin/pg_waldump/archive_waldump.c | 2 +-
src/bin/pg_waldump/pg_waldump.c | 10 +++----
src/common/controldata_utils.c | 6 ++--
src/include/access/xlogreader.h | 6 ++--
src/interfaces/libpq/fe-lobj.c | 4 +--
src/test/examples/testlo.c | 6 ++--
src/test/examples/testlo64.c | 4 +--
39 files changed, 183 insertions(+), 150 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2026-07-15 09:05:31 pgsql: Clean up write() return type
Previous Message Peter Eisentraut 2026-07-15 06:36:22 pgsql: Clean up secure_read()/secure_write() return type