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 <[email protected]>
Discussion: 
https://www.postgresql.org/message-id/flat/[email protected]

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(-)

Reply via email to