agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Clean up read() return type
Date: Wed, 15 Jul 2026 07:50:07 +0000
Message-ID: <E1wjuNa-000GNL-1Q@gemulon.postgresql.org> (raw)
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@iki.fi>
Discussion: https://www.postgresql.org/message-id/flat/f9aab072-0078-49e4-ab93-3b08086a4406@eisentraut.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(-)
Message-ID: <E1wjuNa-000GNL-1Q@gemulon.postgresql.org>
Permalink: ../E1wjuNa-000GNL-1Q@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1wjuNa-000GNL-1Q@gemulon.postgresql.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: peter@eisentraut.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Clean up read() return type
In-Reply-To: <E1wjuNa-000GNL-1Q@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox