pgsql: Fix incorrect data type choices in some read and write calls. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix incorrect data type choices in some read and write calls.
Date
Msg-id E1rIWN2-00CB2k-Ij@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix incorrect data type choices in some read and write calls.

Recently-introduced code in reconstruct.c was using "unsigned"
to store the result of read(), pg_pread(), or write().  This is
completely bogus: it breaks subsequent tests for the result being
negative, as we're being reminded of by a chorus of buildfarm
warnings.  Switch to "int" as was doubtless intended.  (There are
several other uses of "unsigned" in this file that also look poorly
chosen to me, but for now I'm just trying to clean up the buildfarm.)

A larger problem is that "int" is not necessarily wide enough to hold
the result: per POSIX, all these functions return ssize_t.  In places
where the requested read or write length clearly fits in int, that's
academic.  It may be academic anyway as long as we constrain
individual data files to 1GB, since even a readv or writev-like
operation would then not be responsible for transferring more than
1GB.  Nonetheless it seems like trouble waiting to happen, so I made
a pass over readv and writev calls and fixed the result variables
where that seemed appropriate.  We might want to think about changing
some of the fd.c functions to return ssize_t too, for future-proofing;
but I didn't tackle that here.

Discussion: https://postgr.es/m/1672202.1703441340@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/98c6231d198a98b1c5ec9d400cd5593752fa9de9

Modified Files
--------------
src/backend/access/transam/xlog.c      |  2 +-
src/backend/backup/basebackup.c        | 12 ++++++------
src/bin/pg_combinebackup/reconstruct.c | 16 ++++++++--------
3 files changed, 15 insertions(+), 15 deletions(-)


pgsql-committers by date:

Previous
From: Robert Haas
Date:
Subject: pgsql: Initialize variable to placate compiler.
Next
From: Peter Eisentraut
Date:
Subject: pgsql: Fix a warning in Perl test code