]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Clean up read() return type
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 15 Jul 2026 07:43:03 +0000 (09:43 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 15 Jul 2026 07:43:03 +0000 (09:43 +0200)
commitca326e903df4b2efcc7b9090abc4d1a9c27c3088
tree036dfa0e7e94e7094433b7fe106cfd765c5f04e5
parent7d45a6dc19743d999f5c83c95ad144a0f2eb6745
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
39 files changed:
contrib/basic_archive/basic_archive.c
src/backend/access/transam/timeline.c
src/backend/access/transam/twophase.c
src/backend/access/transam/xlog.c
src/backend/access/transam/xlogreader.c
src/backend/access/transam/xlogrecovery.c
src/backend/access/transam/xlogutils.c
src/backend/libpq/be-fsstubs.c
src/backend/postmaster/syslogger.c
src/backend/replication/logical/origin.c
src/backend/replication/logical/reorderbuffer.c
src/backend/replication/logical/snapbuild.c
src/backend/replication/slot.c
src/backend/replication/walsender.c
src/backend/storage/file/buffile.c
src/backend/storage/file/copydir.c
src/backend/storage/ipc/waiteventset.c
src/backend/storage/smgr/md.c
src/backend/utils/cache/relmapper.c
src/backend/utils/init/miscinit.c
src/backend/utils/probes.d
src/bin/pg_basebackup/pg_basebackup.c
src/bin/pg_basebackup/pg_receivewal.c
src/bin/pg_checksums/pg_checksums.c
src/bin/pg_combinebackup/load_manifest.c
src/bin/pg_combinebackup/pg_combinebackup.c
src/bin/pg_combinebackup/reconstruct.c
src/bin/pg_ctl/pg_ctl.c
src/bin/pg_resetwal/pg_resetwal.c
src/bin/pg_rewind/file_ops.c
src/bin/pg_rewind/parsexlog.c
src/bin/pg_verifybackup/pg_verifybackup.c
src/bin/pg_waldump/archive_waldump.c
src/bin/pg_waldump/pg_waldump.c
src/common/controldata_utils.c
src/include/access/xlogreader.h
src/interfaces/libpq/fe-lobj.c
src/test/examples/testlo.c
src/test/examples/testlo64.c