]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
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)
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

index 914a0b56d162fe5ba2454209fa445cca1341f271..532311a6406772b0201c56908d9b1275b2dc36dd 100644 (file)
@@ -245,9 +245,9 @@ compare_files(const char *file1, const char *file2)
 
        for (;;)
        {
-               int                     nbytes = 0;
-               int                     buf1_len = 0;
-               int                     buf2_len = 0;
+               ssize_t         nbytes = 0;
+               size_t          buf1_len = 0;
+               size_t          buf2_len = 0;
 
                while (buf1_len < CMP_BUF_SIZE)
                {
index d49e52993b79640171fe677d071aeec761b2b7e2..db101b761eea021f6988e4bb92922f61854b20b3 100644 (file)
@@ -311,7 +311,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
        char            buffer[BLCKSZ];
        int                     srcfd;
        int                     fd;
-       int                     nbytes;
+       ssize_t         nbytes;
 
        Assert(newTLI > parentTLI); /* else bad selection of newTLI */
 
@@ -355,7 +355,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
                {
                        errno = 0;
                        pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_READ);
-                       nbytes = (int) read(srcfd, buffer, sizeof(buffer));
+                       nbytes = read(srcfd, buffer, sizeof(buffer));
                        pgstat_report_wait_end();
                        if (nbytes < 0 || errno != 0)
                                ereport(ERROR,
@@ -365,7 +365,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
                                break;
                        errno = 0;
                        pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_WRITE);
-                       if ((int) write(fd, buffer, nbytes) != nbytes)
+                       if (write(fd, buffer, nbytes) != nbytes)
                        {
                                int                     save_errno = errno;
 
@@ -409,7 +409,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
        nbytes = strlen(buffer);
        errno = 0;
        pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_WRITE);
-       if ((int) write(fd, buffer, nbytes) != nbytes)
+       if (write(fd, buffer, nbytes) != nbytes)
        {
                int                     save_errno = errno;
 
index e27efcaab471a9669ac99693984c2c21a521796a..69c12226b7b7ec5a511b0a4540c2a46f7423e733 100644 (file)
@@ -1301,6 +1301,7 @@ static char *
 ReadTwoPhaseFile(FullTransactionId fxid, bool missing_ok)
 {
        char            path[MAXPGPATH];
+       size_t          buflen;
        char       *buf;
        TwoPhaseFileHeader *hdr;
        int                     fd;
@@ -1308,7 +1309,7 @@ ReadTwoPhaseFile(FullTransactionId fxid, bool missing_ok)
        uint32          crc_offset;
        pg_crc32c       calc_crc,
                                file_crc;
-       int                     r;
+       ssize_t         r;
 
        TwoPhaseFilePath(path, fxid);
 
@@ -1355,11 +1356,12 @@ ReadTwoPhaseFile(FullTransactionId fxid, bool missing_ok)
        /*
         * OK, slurp in the file.
         */
-       buf = (char *) palloc(stat.st_size);
+       buflen = stat.st_size;
+       buf = (char *) palloc(buflen);
 
        pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_READ);
-       r = read(fd, buf, stat.st_size);
-       if (r != stat.st_size)
+       r = read(fd, buf, buflen);
+       if (r != buflen)
        {
                if (r < 0)
                        ereport(ERROR,
@@ -1367,8 +1369,8 @@ ReadTwoPhaseFile(FullTransactionId fxid, bool missing_ok)
                                         errmsg("could not read file \"%s\": %m", path)));
                else
                        ereport(ERROR,
-                                       (errmsg("could not read file \"%s\": read %d of %lld",
-                                                       path, r, (long long int) stat.st_size)));
+                                       (errmsg("could not read file \"%s\": read %zd of %zu",
+                                                       path, r, buflen)));
        }
 
        pgstat_report_wait_end();
index a9d0ab312c8919d86aee04856c6877535371adac..291692368961fc709e3fe4d3bcefed80a4f9db1a 100644 (file)
@@ -3505,7 +3505,7 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno,
         */
        for (nbytes = 0; nbytes < wal_segment_size; nbytes += sizeof(buffer))
        {
-               int                     nread;
+               ssize_t         nread;
 
                nread = upto - nbytes;
 
@@ -3518,7 +3518,7 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno,
 
                if (nread > 0)
                {
-                       int                     r;
+                       ssize_t         r;
 
                        if (nread > sizeof(buffer))
                                nread = sizeof(buffer);
@@ -3534,8 +3534,8 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno,
                                else
                                        ereport(ERROR,
                                                        (errcode(ERRCODE_DATA_CORRUPTED),
-                                                        errmsg("could not read file \"%s\": read %d of %zu",
-                                                                       path, r, (Size) nread)));
+                                                        errmsg("could not read file \"%s\": read %zd of %zu",
+                                                                       path, r, nread)));
                        }
                        pgstat_report_wait_end();
                }
@@ -4407,7 +4407,7 @@ ReadControlFile(void)
        pg_crc32c       crc;
        int                     fd;
        char            wal_segsz_str[20];
-       int                     r;
+       ssize_t         r;
 
        /*
         * Read data...
@@ -4432,7 +4432,7 @@ ReadControlFile(void)
                else
                        ereport(PANIC,
                                        (errcode(ERRCODE_DATA_CORRUPTED),
-                                        errmsg("could not read file \"%s\": read %d of %zu",
+                                        errmsg("could not read file \"%s\": read %zd of %zu",
                                                        XLOG_CONTROL_FILE, r, sizeof(ControlFileData))));
        }
        pgstat_report_wait_end();
index 9d64ae34932bd0f2d1d8081af74a4e5297195557..946907a2507d30648ac9b0fcd98513b325d2fff2 100644 (file)
@@ -1548,8 +1548,8 @@ WALRead(XLogReaderState *state,
        while (nbytes > 0)
        {
                uint32          startoff;
-               int                     segbytes;
-               int                     readbytes;
+               size_t          segbytes;
+               ssize_t         readbytes;
 
                startoff = XLogSegmentOffset(recptr, state->segcxt.ws_segsize);
 
index c0ae4d3f63fe479f2058bdf60892bfa35c71a16d..a9ebac2d0ef31688591e771a690204e7a9b2723f 100644 (file)
@@ -3282,7 +3282,7 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
        int                     emode = private->emode;
        uint32          targetPageOff;
        XLogSegNo       targetSegNo PG_USED_FOR_ASSERTS_ONLY;
-       int                     r;
+       ssize_t         r;
        instr_time      io_start;
 
        Assert(AmStartupProcess() || !IsUnderPostmaster);
@@ -3408,7 +3408,7 @@ retry:
                else
                        ereport(emode_for_corrupt_record(emode, targetPagePtr + reqLen),
                                        (errcode(ERRCODE_DATA_CORRUPTED),
-                                        errmsg("could not read from WAL segment %s, LSN %X/%08X, offset %u: read %d of %zu",
+                                        errmsg("could not read from WAL segment %s, LSN %X/%08X, offset %u: read %zd of %zu",
                                                        fname, LSN_FORMAT_ARGS(targetPagePtr),
                                                        readOff, r, (Size) XLOG_BLCKSZ)));
                goto next_record_is_invalid;
index d8c179c5dccb25a0f9b600b5090bbd8d1513a0f6..58b9dab6a90870058a4dfa7aa70c36c3dd123938 100644 (file)
@@ -1056,14 +1056,14 @@ WALReadRaiseError(WALReadError *errinfo)
                errno = errinfo->wre_errno;
                ereport(ERROR,
                                (errcode_for_file_access(),
-                                errmsg("could not read from WAL segment %s, offset %d: %m",
+                                errmsg("could not read from WAL segment %s, offset %u: %m",
                                                fname, errinfo->wre_off)));
        }
        else if (errinfo->wre_read == 0)
        {
                ereport(ERROR,
                                (errcode(ERRCODE_DATA_CORRUPTED),
-                                errmsg("could not read from WAL segment %s, offset %d: read %d of %d",
+                                errmsg("could not read from WAL segment %s, offset %u: read %zd of %zu",
                                                fname, errinfo->wre_off, errinfo->wre_read,
                                                errinfo->wre_req)));
        }
index f27e374c4eeedbb8e5f2d2bbb8323b7fea1d75b7..1aa4a3080f51b5d73db1189fabf73462ad538ed0 100644 (file)
@@ -424,8 +424,8 @@ static Oid
 lo_import_internal(text *filename, Oid lobjOid)
 {
        int                     fd;
-       int                     nbytes,
-                               tmp PG_USED_FOR_ASSERTS_ONLY;
+       ssize_t         nbytes;
+       int                     tmp PG_USED_FOR_ASSERTS_ONLY;
        char            buf[BUFSIZE];
        char            fnamebuf[MAXPGPATH];
        LargeObjectDesc *lobj;
index 7645c495a815c686145ae76e4d41657eb5a85ea5..b4b599c4c69f3aea23af757839067e019c8bf926 100644 (file)
@@ -533,7 +533,7 @@ SysLoggerMain(const void *startup_data, size_t startup_data_len)
 
                if (rc == 1 && event.events == WL_SOCKET_READABLE)
                {
-                       int                     bytesRead;
+                       ssize_t         bytesRead;
 
                        bytesRead = read(syslogPipe[0],
                                                         logbuffer + bytes_in_logbuffer,
index c9dfb094c2b1699ee39298a125f92cb413b89157..5cb18d851ae76e8970468a175c65f704d60b304d 100644 (file)
@@ -741,7 +741,7 @@ StartupReplicationOrigin(void)
 {
        const char *path = PG_REPLORIGIN_CHECKPOINT_FILENAME;
        int                     fd;
-       int                     readBytes;
+       ssize_t         readBytes;
        uint32          magic = REPLICATION_STATE_MAGIC;
        int                     last_state = 0;
        pg_crc32c       file_crc;
@@ -788,7 +788,7 @@ StartupReplicationOrigin(void)
                else
                        ereport(PANIC,
                                        (errcode(ERRCODE_DATA_CORRUPTED),
-                                        errmsg("could not read file \"%s\": read %d of %zu",
+                                        errmsg("could not read file \"%s\": read %zd of %zu",
                                                        path, readBytes, sizeof(magic))));
        }
        COMP_CRC32C(crc, &magic, sizeof(magic));
@@ -826,7 +826,7 @@ StartupReplicationOrigin(void)
                {
                        ereport(PANIC,
                                        (errcode_for_file_access(),
-                                        errmsg("could not read file \"%s\": read %d of %zu",
+                                        errmsg("could not read file \"%s\": read %zd of %zu",
                                                        path, readBytes, sizeof(disk_state))));
                }
 
index d06d0d8c9be228b92313e7f509ae81cc3d9fe9f3..6df6166d8a7419bf64f4a8b3b8a91d25338e947a 100644 (file)
@@ -4561,7 +4561,7 @@ ReorderBufferRestoreChanges(ReorderBuffer *rb, ReorderBufferTXN *txn,
 
        while (restored < max_changes_in_memory && *segno <= last_segno)
        {
-               int                     readBytes;
+               ssize_t         readBytes;
                ReorderBufferDiskChange *ondisk;
 
                CHECK_FOR_INTERRUPTS();
@@ -4626,9 +4626,9 @@ ReorderBufferRestoreChanges(ReorderBuffer *rb, ReorderBufferTXN *txn,
                else if (readBytes != sizeof(ReorderBufferDiskChange))
                        ereport(ERROR,
                                        (errcode_for_file_access(),
-                                        errmsg("could not read from reorderbuffer spill file: read %d instead of %u bytes",
+                                        errmsg("could not read from reorderbuffer spill file: read %zd of %zu",
                                                        readBytes,
-                                                       (uint32) sizeof(ReorderBufferDiskChange))));
+                                                       sizeof(ReorderBufferDiskChange))));
 
                file->curOffset += readBytes;
 
@@ -4651,9 +4651,9 @@ ReorderBufferRestoreChanges(ReorderBuffer *rb, ReorderBufferTXN *txn,
                else if (readBytes != ondisk->size - sizeof(ReorderBufferDiskChange))
                        ereport(ERROR,
                                        (errcode_for_file_access(),
-                                        errmsg("could not read from reorderbuffer spill file: read %d instead of %u bytes",
+                                        errmsg("could not read from reorderbuffer spill file: read %zd of %zu",
                                                        readBytes,
-                                                       (uint32) (ondisk->size - sizeof(ReorderBufferDiskChange)))));
+                                                       (ondisk->size - sizeof(ReorderBufferDiskChange)))));
 
                file->curOffset += readBytes;
 
@@ -5358,7 +5358,7 @@ ApplyLogicalMappingFile(HTAB *tuplecid_data, const char *fname)
 {
        char            path[MAXPGPATH];
        int                     fd;
-       int                     readBytes;
+       ssize_t         readBytes;
        LogicalRewriteMappingData map;
 
        sprintf(path, "%s/%s", PG_LOGICAL_MAPPINGS_DIR, fname);
@@ -5393,9 +5393,9 @@ ApplyLogicalMappingFile(HTAB *tuplecid_data, const char *fname)
                else if (readBytes != sizeof(LogicalRewriteMappingData))
                        ereport(ERROR,
                                        (errcode_for_file_access(),
-                                        errmsg("could not read from file \"%s\": read %d instead of %d bytes",
+                                        errmsg("could not read from file \"%s\": read %zd of %zu",
                                                        path, readBytes,
-                                                       (int32) sizeof(LogicalRewriteMappingData))));
+                                                       sizeof(LogicalRewriteMappingData))));
 
                key.rlocator = map.old_locator;
                ItemPointerCopy(&map.old_tid,
index b1e37ef679274740f87ee7ffbee549c88be92574..f60bcf096057d14a6ecff4317c4971f31a7ea500 100644 (file)
@@ -1937,7 +1937,7 @@ snapshot_not_interesting:
 static void
 SnapBuildRestoreContents(int fd, void *dest, Size size, const char *path)
 {
-       int                     readBytes;
+       ssize_t         readBytes;
 
        pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_READ);
        readBytes = read(fd, dest, size);
@@ -1958,7 +1958,7 @@ SnapBuildRestoreContents(int fd, void *dest, Size size, const char *path)
                else
                        ereport(ERROR,
                                        (errcode(ERRCODE_DATA_CORRUPTED),
-                                        errmsg("could not read file \"%s\": read %d of %zu",
+                                        errmsg("could not read file \"%s\": read %zd of %zu",
                                                        path, readBytes, size)));
        }
 }
index d7fb9f5a67ffd1ac9a2c98cb0a9281b814bbb258..c7ab82a28e191977f5627de2c99048a914b8ddf1 100644 (file)
@@ -2688,7 +2688,7 @@ RestoreSlotFromDisk(const char *name)
        char            path[MAXPGPATH + sizeof(PG_REPLSLOT_DIR) + 10];
        int                     fd;
        bool            restored = false;
-       int                     readBytes;
+       ssize_t         readBytes;
        pg_crc32c       checksum;
        TimestampTz now = 0;
 
@@ -2748,9 +2748,9 @@ RestoreSlotFromDisk(const char *name)
                else
                        ereport(PANIC,
                                        (errcode(ERRCODE_DATA_CORRUPTED),
-                                        errmsg("could not read file \"%s\": read %d of %zu",
+                                        errmsg("could not read file \"%s\": read %zd of %zu",
                                                        path, readBytes,
-                                                       (Size) ReplicationSlotOnDiskConstantSize)));
+                                                       ReplicationSlotOnDiskConstantSize)));
        }
 
        /* verify magic */
@@ -2789,7 +2789,7 @@ RestoreSlotFromDisk(const char *name)
                else
                        ereport(PANIC,
                                        (errcode(ERRCODE_DATA_CORRUPTED),
-                                        errmsg("could not read file \"%s\": read %d of %zu",
+                                        errmsg("could not read file \"%s\": read %zd of %zu",
                                                        path, readBytes, (Size) cp.length)));
        }
 
index ae9ffd0d096bc7ddd3b07145bf8589ac8a59663f..35ebc7e61c8c5448c7c5143462d79c7fc948f862 100644 (file)
@@ -617,7 +617,7 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
        char            path[MAXPGPATH];
        int                     fd;
        off_t           histfilelen;
-       off_t           bytesleft;
+       size_t          bytesleft;
        Size            len;
 
        dest = CreateDestReceiver(DestRemoteSimple);
@@ -673,7 +673,7 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
        while (bytesleft > 0)
        {
                PGAlignedBlock rbuf;
-               int                     nread;
+               ssize_t         nread;
 
                pgstat_report_wait_start(WAIT_EVENT_WALSENDER_TIMELINE_HISTORY_READ);
                nread = read(fd, rbuf.data, sizeof(rbuf));
@@ -686,10 +686,20 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
                else if (nread == 0)
                        ereport(ERROR,
                                        (errcode(ERRCODE_DATA_CORRUPTED),
-                                        errmsg("could not read file \"%s\": read %d of %zu",
-                                                       path, nread, (Size) bytesleft)));
+                                        errmsg("could not read file \"%s\": read %zd of %zu",
+                                                       path, nread, bytesleft)));
+
+               /*
+                * We could have read more than expected if the file changed
+                * concurrently.  In that case, only send as much as we expected and
+                * make sure the loop aborts properly (no wrap of bytesleft).  (This
+                * isn't possible in practice, because the files are updated by atomic
+                * renames, but it's a safer programming practice.)
+                */
+               nread = Min(nread, bytesleft);
 
                pq_sendbytes(&buf, rbuf.data, nread);
+
                bytesleft -= nread;
        }
 
index c4afe4d368a3441aec203c5e411040a7b4bdb15b..b44d24cdbd36fb4281ddcafb8abe607118c119a2 100644 (file)
@@ -437,6 +437,7 @@ BufFileLoadBuffer(BufFile *file)
        File            thisfile;
        instr_time      io_start;
        instr_time      io_time;
+       ssize_t         rc;
 
        /*
         * Advance to next component file if necessary and possible.
@@ -458,12 +459,12 @@ BufFileLoadBuffer(BufFile *file)
        /*
         * Read whatever we can get, up to a full bufferload.
         */
-       file->nbytes = FileRead(thisfile,
-                                                       file->buffer.data,
-                                                       sizeof(file->buffer.data),
-                                                       file->curOffset,
-                                                       WAIT_EVENT_BUFFILE_READ);
-       if (file->nbytes < 0)
+       rc = FileRead(thisfile,
+                                 file->buffer.data,
+                                 sizeof(file->buffer.data),
+                                 file->curOffset,
+                                 WAIT_EVENT_BUFFILE_READ);
+       if (rc < 0)
        {
                file->nbytes = 0;
                ereport(ERROR,
@@ -472,6 +473,8 @@ BufFileLoadBuffer(BufFile *file)
                                                FilePathName(thisfile))));
        }
 
+       file->nbytes = rc;
+
        if (track_io_timing)
        {
                INSTR_TIME_SET_CURRENT(io_time);
index 5ee141f13a53880b2a5fd002e0591b2e6d476ae1..ee42c796f773a92bdb222dddbdee91dc417903aa 100644 (file)
@@ -136,7 +136,7 @@ copy_file(const char *fromfile, const char *tofile)
        char       *buffer;
        int                     srcfd;
        int                     dstfd;
-       int                     nbytes;
+       ssize_t         nbytes;
        off_t           offset;
        off_t           flush_offset;
 
@@ -204,7 +204,7 @@ copy_file(const char *fromfile, const char *tofile)
                        break;
                errno = 0;
                pgstat_report_wait_start(WAIT_EVENT_COPY_FILE_WRITE);
-               if ((int) write(dstfd, buffer, nbytes) != nbytes)
+               if (write(dstfd, buffer, nbytes) != nbytes)
                {
                        /* if write didn't set errno, assume problem is no disk space */
                        if (errno == 0)
index 627dba0a842dcee7e52e70c87fb9752e3d979423..880c05dd6477f1bce160092b60650897367977e2 100644 (file)
@@ -1947,7 +1947,7 @@ static void
 drain(void)
 {
        char            buf[1024];
-       int                     rc;
+       ssize_t         rc;
        int                     fd;
 
 #ifdef WAIT_USE_SELF_PIPE
index 718c1cfc0f9dfe06a473ad1e10883daab1b4cc3d..79febf12de3fd36f941040065ee03130299112e9 100644 (file)
@@ -863,7 +863,7 @@ mdreadv(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
                struct iovec iov[PG_IOV_MAX];
                int                     iovcnt;
                pgoff_t         seekpos;
-               int                     nbytes;
+               ssize_t         nbytes;
                MdfdVec    *v;
                BlockNumber nblocks_this_segment;
                size_t          transferred_this_segment;
index 3aaf466868d464b97ab38ac838fce3a3f69a315b..ca7f1b690074ad6a401c7fa63f17983b223feee5 100644 (file)
@@ -787,7 +787,7 @@ read_relmap_file(RelMapFile *map, char *dbpath, bool lock_held, int elevel)
        char            mapfilename[MAXPGPATH];
        pg_crc32c       crc;
        int                     fd;
-       int                     r;
+       ssize_t         r;
 
        Assert(elevel >= ERROR);
 
@@ -831,7 +831,7 @@ read_relmap_file(RelMapFile *map, char *dbpath, bool lock_held, int elevel)
                else
                        ereport(elevel,
                                        (errcode(ERRCODE_DATA_CORRUPTED),
-                                        errmsg("could not read file \"%s\": read %d of %zu",
+                                        errmsg("could not read file \"%s\": read %zd of %zu",
                                                        mapfilename, r, sizeof(RelMapFile))));
        }
        pgstat_report_wait_end();
index 7ffc808073ac84054427a7d710f1ecfcdf8b8049..263ae7b8d8603b1c36bf5848e1e23e001d442e2d 100644 (file)
@@ -1164,7 +1164,6 @@ CreateLockFile(const char *filename, bool amPostmaster,
        int                     fd;
        char            buffer[MAXPGPATH * 2 + 256];
        int                     ntries;
-       int                     len;
        int                     encoded_pid;
        pid_t           other_pid;
        pid_t           my_pid,
@@ -1216,6 +1215,8 @@ CreateLockFile(const char *filename, bool amPostmaster,
         */
        for (ntries = 0;; ntries++)
        {
+               ssize_t         len;
+
                /*
                 * Try to create the lock file --- O_EXCL makes this atomic.
                 *
@@ -1521,7 +1522,7 @@ void
 AddToDataDirLockFile(int target_line, const char *str)
 {
        int                     fd;
-       int                     len;
+       ssize_t         len;
        int                     lineno;
        char       *srcptr;
        char       *destptr;
@@ -1648,7 +1649,7 @@ bool
 RecheckDataDirLockFile(void)
 {
        int                     fd;
-       int                     len;
+       ssize_t         len;
        long            file_pid;
        char            buffer[BLCKSZ];
 
index 1929521c6a56ab33b4bb806bc7bb1786c8946233..48b269468a5fda26708cbb38213fffd7e50df6a3 100644 (file)
@@ -83,7 +83,7 @@ provider postgresql {
        probe twophase__checkpoint__done();
 
        probe smgr__md__read__start(ForkNumber, BlockNumber, Oid, Oid, Oid, int);
-       probe smgr__md__read__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int);
+       probe smgr__md__read__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, long long int, long long int);
        probe smgr__md__write__start(ForkNumber, BlockNumber, Oid, Oid, Oid, int);
        probe smgr__md__write__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int);
 
index c82852e6be0f857a305748818d5e047361de5147..8a599fc986908cfbff2af5c8e5d599bb98c7d72d 100644 (file)
@@ -480,12 +480,13 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
                r = select(bgpipe[0] + 1, &fds, NULL, NULL, &tv);
                if (r == 1)
                {
+                       ssize_t         nread;
                        char            xlogend[64] = {0};
                        uint32          hi,
                                                lo;
 
-                       r = read(bgpipe[0], xlogend, sizeof(xlogend) - 1);
-                       if (r < 0)
+                       nread = read(bgpipe[0], xlogend, sizeof(xlogend) - 1);
+                       if (nread < 0)
                                pg_fatal("could not read from ready pipe: %m");
 
                        if (sscanf(xlogend, "%X/%08X", &hi, &lo) != 2)
@@ -1822,7 +1823,7 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
        {
                int                     fd;
                char            mbuf[65536];
-               int                     nbytes;
+               ssize_t         nbytes;
 
                /* Reject if server is too old. */
                if (serverVersion < MINIMUM_VERSION_FOR_WAL_SUMMARIES)
index ddfec298fb7a1e4732a487b8ff7c099a65102678..20506fc3560bb6de003e8b99733509586b9c12eb 100644 (file)
@@ -331,7 +331,7 @@ FindStreamingStart(uint32 *tli)
                        char            buf[4];
                        int                     bytes_out;
                        char            fullpath[MAXPGPATH * 2];
-                       int                     r;
+                       ssize_t         r;
 
                        snprintf(fullpath, sizeof(fullpath), "%s/%s", basedir, dirent->d_name);
 
@@ -349,7 +349,7 @@ FindStreamingStart(uint32 *tli)
                                        pg_fatal("could not read compressed file \"%s\": %m",
                                                         fullpath);
                                else
-                                       pg_fatal("could not read compressed file \"%s\": read %d of %zu",
+                                       pg_fatal("could not read compressed file \"%s\": read %zd of %zu",
                                                         fullpath, r, sizeof(buf));
                        }
 
index cfacd1300fc1d98dcf1e140bcec6a9396a6cc71b..412c9a18f95109052878e9604feb11701139b797 100644 (file)
@@ -196,8 +196,9 @@ scan_file(const char *fn, int segmentno)
        for (blockno = 0;; blockno++)
        {
                uint16          csum;
-               int                     r = read(f, buf.data, BLCKSZ);
+               ssize_t         r;
 
+               r = read(f, buf.data, BLCKSZ);
                if (r == 0)
                        break;
                if (r != BLCKSZ)
@@ -206,8 +207,8 @@ scan_file(const char *fn, int segmentno)
                                pg_fatal("could not read block %u in file \"%s\": %m",
                                                 blockno, fn);
                        else
-                               pg_fatal("could not read block %u in file \"%s\": read %d of %d",
-                                                blockno, fn, r, BLCKSZ);
+                               pg_fatal("could not read block %u in file \"%s\": read %zd of %zu",
+                                                blockno, fn, r, (size_t) BLCKSZ);
                }
                blocks_scanned++;
 
index 1a3eb99c10d9887f8ac198958005ae15e70387a4..9d2cc1e53adc7cd89a665e30fd66ddba94e55155 100644 (file)
@@ -111,10 +111,10 @@ load_backup_manifest(char *backup_directory)
        uint32          initial_size;
        manifest_files_hash *ht;
        char       *buffer;
-       int                     rc;
        JsonManifestParseContext context;
        manifest_data *result;
-       int                     chunk_size = READ_CHUNK_SIZE;
+       size_t          total_size;
+       const size_t chunk_size = READ_CHUNK_SIZE;
 
        /* Open the manifest file. */
        snprintf(pathname, MAXPGPATH, "%s/backup_manifest", backup_directory);
@@ -148,31 +148,35 @@ load_backup_manifest(char *backup_directory)
        context.per_wal_range_cb = combinebackup_per_wal_range_cb;
        context.error_cb = report_manifest_error;
 
+       total_size = statbuf.st_size;
+
        /*
         * Parse the file, in chunks if necessary.
         */
-       if (statbuf.st_size <= chunk_size)
+       if (total_size <= chunk_size)
        {
-               buffer = pg_malloc(statbuf.st_size);
-               rc = read(fd, buffer, statbuf.st_size);
-               if (rc != statbuf.st_size)
+               ssize_t         rc;
+
+               buffer = pg_malloc(total_size);
+               rc = read(fd, buffer, total_size);
+               if (rc != total_size)
                {
                        if (rc < 0)
                                pg_fatal("could not read file \"%s\": %m", pathname);
                        else
-                               pg_fatal("could not read file \"%s\": read %d of %lld",
-                                                pathname, rc, (long long int) statbuf.st_size);
+                               pg_fatal("could not read file \"%s\": read %zd of %zu",
+                                                pathname, rc, total_size);
                }
 
                /* Close the manifest file. */
                close(fd);
 
                /* Parse the manifest. */
-               json_parse_manifest(&context, buffer, statbuf.st_size);
+               json_parse_manifest(&context, buffer, total_size);
        }
        else
        {
-               int                     bytes_left = statbuf.st_size;
+               size_t          bytes_left = total_size;
                JsonManifestParseIncrementalState *inc_state;
 
                inc_state = json_parse_manifest_incremental_init(&context);
@@ -181,7 +185,8 @@ load_backup_manifest(char *backup_directory)
 
                while (bytes_left > 0)
                {
-                       int                     bytes_to_read = chunk_size;
+                       ssize_t         rc;
+                       size_t          bytes_to_read = chunk_size;
 
                        /*
                         * Make sure that the last chunk is sufficiently large. (i.e. at
@@ -198,10 +203,10 @@ load_backup_manifest(char *backup_directory)
                                if (rc < 0)
                                        pg_fatal("could not read file \"%s\": %m", pathname);
                                else
-                                       pg_fatal("could not read file \"%s\": read %lld of %lld",
+                                       pg_fatal("could not read file \"%s\": read %zu of %zu",
                                                         pathname,
-                                                        (long long int) (statbuf.st_size + rc - bytes_left),
-                                                        (long long int) statbuf.st_size);
+                                                        total_size + rc - bytes_left,
+                                                        total_size);
                        }
                        bytes_left -= rc;
                        json_parse_manifest_incremental_chunk(inc_state, buffer, rc, bytes_left == 0);
index 2374493307386363c8619b08c9a4a4f1a1d282ef..86e2ee37c4081c0201bd50a9bf3aa2582bddd3b3 100644 (file)
@@ -1346,6 +1346,7 @@ slurp_file(int fd, char *filename, StringInfo buf, int maxlen)
 {
        struct stat st;
        ssize_t         rb;
+       size_t          len;
 
        /* Check file size, and complain if it's too large. */
        if (fstat(fd, &st) != 0)
@@ -1353,23 +1354,25 @@ slurp_file(int fd, char *filename, StringInfo buf, int maxlen)
        if (st.st_size > maxlen)
                pg_fatal("file \"%s\" is too large", filename);
 
+       len = st.st_size;
+
        /* Make sure we have enough space. */
-       enlargeStringInfo(buf, st.st_size);
+       enlargeStringInfo(buf, len);
 
        /* Read the data. */
-       rb = read(fd, &buf->data[buf->len], st.st_size);
+       rb = read(fd, &buf->data[buf->len], len);
 
        /*
         * We don't expect any concurrent changes, so we should read exactly the
         * expected number of bytes.
         */
-       if (rb != st.st_size)
+       if (rb != len)
        {
                if (rb < 0)
                        pg_fatal("could not read file \"%s\": %m", filename);
                else
-                       pg_fatal("could not read file \"%s\": read %zd of %lld",
-                                        filename, rb, (long long int) st.st_size);
+                       pg_fatal("could not read file \"%s\": read %zd of %zu",
+                                        filename, rb, len);
        }
 
        /* Adjust buffer length for new data and restore trailing-\0 invariant */
index 5000f7be0019c444ded944893e7624f752daed49..3c377b749f51d38400c7ade11bdd42a4b6a84d70 100644 (file)
@@ -61,7 +61,7 @@ static void write_reconstructed_file(const char *input_filename,
                                                                         CopyMethod copy_method,
                                                                         bool debug,
                                                                         bool dry_run);
-static void read_bytes(const rfile *rf, void *buffer, unsigned length);
+static void read_bytes(const rfile *rf, void *buffer, size_t length);
 static void write_block(int fd, const char *output_filename,
                                                const uint8 *buffer,
                                                pg_checksum_context *checksum_ctx);
@@ -529,16 +529,18 @@ make_rfile(const char *filename, bool missing_ok)
  * Read the indicated number of bytes from an rfile into the buffer.
  */
 static void
-read_bytes(const rfile *rf, void *buffer, unsigned length)
+read_bytes(const rfile *rf, void *buffer, size_t length)
 {
-       int                     rb = read(rf->fd, buffer, length);
+       ssize_t         rb;
+
+       rb = read(rf->fd, buffer, length);
 
        if (rb != length)
        {
                if (rb < 0)
                        pg_fatal("could not read file \"%s\": %m", rf->filename);
                else
-                       pg_fatal("could not read file \"%s\": read %d of %u",
+                       pg_fatal("could not read file \"%s\": read %zd of %zu",
                                         rf->filename, rb, length);
        }
 }
@@ -776,7 +778,7 @@ write_block(int fd, const char *output_filename,
 static void
 read_block(const rfile *s, off_t off, uint8 *buffer)
 {
-       int                     rb;
+       ssize_t         rb;
 
        /* Read the block from the correct source, except if dry-run. */
        rb = pg_pread(s->fd, buffer, BLCKSZ, off);
@@ -785,7 +787,7 @@ read_block(const rfile *s, off_t off, uint8 *buffer)
                if (rb < 0)
                        pg_fatal("could not read from file \"%s\": %m", s->filename);
                else
-                       pg_fatal("could not read from file \"%s\", offset %lld: read %d of %d",
-                                        s->filename, (long long) off, rb, BLCKSZ);
+                       pg_fatal("could not read from file \"%s\", offset %lld: read %zd of %zu",
+                                        s->filename, (long long) off, rb, (size_t) BLCKSZ);
        }
 }
index 91293f1218ddea98ab015fbc791cc3268ce45d25..6c604e2d9623ee7d2c85deb2b65ed3fbafbbfdc1 100644 (file)
@@ -317,11 +317,11 @@ readfile(const char *path, int *numlines)
        int                     fd;
        int                     nlines;
        char      **result;
+       size_t          buflen;
        char       *buffer;
        char       *linebegin;
-       int                     i;
        int                     n;
-       int                     len;
+       ssize_t         nread;
        struct stat statbuf;
 
        *numlines = 0;                          /* in case of failure or empty file */
@@ -350,11 +350,13 @@ readfile(const char *path, int *numlines)
                *result = NULL;
                return result;
        }
-       buffer = pg_malloc(statbuf.st_size + 1);
 
-       len = read(fd, buffer, statbuf.st_size + 1);
+       buflen = statbuf.st_size + 1;
+       buffer = pg_malloc(buflen);
+
+       nread = read(fd, buffer, buflen);
        close(fd);
-       if (len != statbuf.st_size)
+       if (nread != buflen - 1)
        {
                /* oops, the file size changed between fstat and read */
                pg_free(buffer);
@@ -367,7 +369,7 @@ readfile(const char *path, int *numlines)
         * any characters after the last newline will be ignored.
         */
        nlines = 0;
-       for (i = 0; i < len; i++)
+       for (ssize_t i = 0; i < nread; i++)
        {
                if (buffer[i] == '\n')
                        nlines++;
@@ -380,7 +382,7 @@ readfile(const char *path, int *numlines)
        /* now split the buffer into lines */
        linebegin = buffer;
        n = 0;
-       for (i = 0; i < len; i++)
+       for (ssize_t i = 0; i < nread; i++)
        {
                if (buffer[i] == '\n')
                {
index f8d25afed9de401d97318432b14236f51128e4e9..d072e7c2ea471c1fb81e31155736dc16dea67ff4 100644 (file)
@@ -596,7 +596,7 @@ static bool
 read_controlfile(void)
 {
        int                     fd;
-       int                     len;
+       ssize_t         len;
        char       *buffer;
        pg_crc32c       crc;
 
index 6a3562d8bde724ad89831d7e7a814dab9419cdfe..3bf6296ed0e952bbb5419e5e0605448be426b5d9 100644 (file)
@@ -340,8 +340,8 @@ slurpFile(const char *datadir, const char *path, size_t *filesize)
        char       *buffer;
        struct stat statbuf;
        char            fullpath[MAXPGPATH];
-       int                     len;
-       int                     r;
+       size_t          len;
+       ssize_t         r;
 
        snprintf(fullpath, sizeof(fullpath), "%s/%s", datadir, path);
 
@@ -364,8 +364,8 @@ slurpFile(const char *datadir, const char *path, size_t *filesize)
                        pg_fatal("could not read file \"%s\": %m",
                                         fullpath);
                else
-                       pg_fatal("could not read file \"%s\": read %d of %zu",
-                                        fullpath, r, (Size) len);
+                       pg_fatal("could not read file \"%s\": read %zd of %zu",
+                                        fullpath, r, len);
        }
        close(fd);
 
index db7a7e73042fbd61e9c1d32aabef236249f9a204..023e23b063c1565186403cebb3dd1dbccb0e82e5 100644 (file)
@@ -279,7 +279,7 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
        uint32          targetPageOff;
        XLogRecPtr      targetSegEnd;
        XLogSegNo       targetSegNo;
-       int                     r;
+       ssize_t         r;
 
        XLByteToSeg(targetPagePtr, targetSegNo, WalSegSz);
        XLogSegNoOffsetToRecPtr(targetSegNo + 1, 0, WalSegSz, targetSegEnd);
@@ -370,9 +370,8 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
                if (r < 0)
                        pg_log_error("could not read file \"%s\": %m", xlogfpath);
                else
-                       pg_log_error("could not read file \"%s\": read %d of %zu",
+                       pg_log_error("could not read file \"%s\": read %zd of %zu",
                                                 xlogfpath, r, (Size) XLOG_BLCKSZ);
-
                return -1;
        }
 
index 97f575944cd3c4c1ba49486be159ad80ead33590..05385a91e886b3ea1e1ff0ab1c86e48eca612b9c 100644 (file)
@@ -412,11 +412,10 @@ parse_manifest_file(char *manifest_path)
        uint32          initial_size;
        manifest_files_hash *ht;
        char       *buffer;
-       int                     rc;
        JsonManifestParseContext context;
        manifest_data *result;
-
-       int                     chunk_size = READ_CHUNK_SIZE;
+       size_t          total_size;
+       const size_t chunk_size = READ_CHUNK_SIZE;
 
        /* Open the manifest file. */
        if ((fd = open(manifest_path, O_RDONLY | PG_BINARY, 0)) < 0)
@@ -442,31 +441,35 @@ parse_manifest_file(char *manifest_path)
        context.per_wal_range_cb = verifybackup_per_wal_range_cb;
        context.error_cb = report_manifest_error;
 
+       total_size = statbuf.st_size;
+
        /*
         * Parse the file, in chunks if necessary.
         */
-       if (statbuf.st_size <= chunk_size)
+       if (total_size <= chunk_size)
        {
-               buffer = pg_malloc(statbuf.st_size);
-               rc = read(fd, buffer, statbuf.st_size);
-               if (rc != statbuf.st_size)
+               ssize_t         rc;
+
+               buffer = pg_malloc(total_size);
+               rc = read(fd, buffer, total_size);
+               if (rc != total_size)
                {
                        if (rc < 0)
                                pg_fatal("could not read file \"%s\": %m", manifest_path);
                        else
-                               pg_fatal("could not read file \"%s\": read %d of %lld",
-                                                manifest_path, rc, (long long int) statbuf.st_size);
+                               pg_fatal("could not read file \"%s\": read %zd of %zu",
+                                                manifest_path, rc, total_size);
                }
 
                /* Close the manifest file. */
                close(fd);
 
                /* Parse the manifest. */
-               json_parse_manifest(&context, buffer, statbuf.st_size);
+               json_parse_manifest(&context, buffer, total_size);
        }
        else
        {
-               int                     bytes_left = statbuf.st_size;
+               size_t          bytes_left = total_size;
                JsonManifestParseIncrementalState *inc_state;
 
                inc_state = json_parse_manifest_incremental_init(&context);
@@ -475,7 +478,8 @@ parse_manifest_file(char *manifest_path)
 
                while (bytes_left > 0)
                {
-                       int                     bytes_to_read = chunk_size;
+                       ssize_t         rc;
+                       size_t          bytes_to_read = chunk_size;
 
                        /*
                         * Make sure that the last chunk is sufficiently large. (i.e. at
@@ -492,10 +496,10 @@ parse_manifest_file(char *manifest_path)
                                if (rc < 0)
                                        pg_fatal("could not read file \"%s\": %m", manifest_path);
                                else
-                                       pg_fatal("could not read file \"%s\": read %lld of %lld",
+                                       pg_fatal("could not read file \"%s\": read %zu of %zu",
                                                         manifest_path,
-                                                        (long long int) (statbuf.st_size + rc - bytes_left),
-                                                        (long long int) statbuf.st_size);
+                                                        total_size + rc - bytes_left,
+                                                        total_size);
                        }
                        bytes_left -= rc;
                        json_parse_manifest_incremental_chunk(inc_state, buffer, rc,
@@ -1016,7 +1020,7 @@ verify_tar_file(verifier_context *context, char *relpath, char *fullpath,
                                astreamer *streamer)
 {
        int                     fd;
-       int                     rc;
+       ssize_t         rc;
        char       *buffer;
 
        pg_log_debug("reading \"%s\"", fullpath);
@@ -1124,7 +1128,7 @@ verify_file_checksum(verifier_context *context, manifest_file *m,
        pg_checksum_context checksum_ctx;
        const char *relpath = m->pathname;
        int                     fd;
-       int                     rc;
+       ssize_t         rc;
        uint64          bytes_read = 0;
        uint8           checksumbuf[PG_CHECKSUM_MAX_LENGTH];
        int                     checksumlen;
index 0f44ebfeb2001a7cd609ab1e800b936dca9c92a9..e0c3aa4d255b13ec62be96d9c04cde6f6bcd532e 100644 (file)
@@ -535,7 +535,7 @@ get_archive_wal_entry(const char *fname, XLogDumpPrivate *privateInfo)
 static bool
 read_archive_file(XLogDumpPrivate *privateInfo)
 {
-       int                     rc;
+       ssize_t         rc;
 
        /* Fail if we already reached EOF in a prior call. */
        if (privateInfo->archive_fd_eof)
index c777e6763e5cf9e3d41c8f49081f58776a791356..cf760d8b236e11f7e5d19472805057780f26dec8 100644 (file)
@@ -236,7 +236,7 @@ search_directory(const char *directory, const char *fname, int *WalSegSz)
        if (fd >= 0)
        {
                PGAlignedXLogBlock buf;
-               int                     r;
+               ssize_t         r;
 
                r = read(fd, buf.data, XLOG_BLCKSZ);
                if (r == XLOG_BLCKSZ)
@@ -259,8 +259,8 @@ search_directory(const char *directory, const char *fname, int *WalSegSz)
                        pg_fatal("could not read file \"%s\": %m",
                                         fname);
                else
-                       pg_fatal("could not read file \"%s\": read %d of %d",
-                                        fname, r, XLOG_BLCKSZ);
+                       pg_fatal("could not read file \"%s\": read %zd of %zu",
+                                        fname, r, (size_t) XLOG_BLCKSZ);
                close(fd);
                return true;
        }
@@ -430,11 +430,11 @@ WALDumpReadPage(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen,
                if (errinfo.wre_errno != 0)
                {
                        errno = errinfo.wre_errno;
-                       pg_fatal("could not read from file \"%s\", offset %d: %m",
+                       pg_fatal("could not read from file \"%s\", offset %u: %m",
                                         fname, errinfo.wre_off);
                }
                else
-                       pg_fatal("could not read from file \"%s\", offset %d: read %d of %d",
+                       pg_fatal("could not read from file \"%s\", offset %u: read %zd of %zu",
                                         fname, errinfo.wre_off, errinfo.wre_read,
                                         errinfo.wre_req);
        }
index 4ab116afcdef6cb35f2721fcefc529b799ee25e1..0e8e03c566cee15c78c0356db3ea4da30c6294b2 100644 (file)
@@ -71,7 +71,7 @@ get_controlfile_by_exact_path(const char *ControlFilePath, bool *crc_ok_p)
        ControlFileData *ControlFile;
        int                     fd;
        pg_crc32c       crc;
-       int                     r;
+       ssize_t         r;
 #ifdef FRONTEND
        pg_crc32c       last_crc;
        int                     retries = 0;
@@ -114,10 +114,10 @@ retry:
 #ifndef FRONTEND
                        ereport(ERROR,
                                        (errcode(ERRCODE_DATA_CORRUPTED),
-                                        errmsg("could not read file \"%s\": read %d of %zu",
+                                        errmsg("could not read file \"%s\": read %zd of %zu",
                                                        ControlFilePath, r, sizeof(ControlFileData))));
 #else
-                       pg_fatal("could not read file \"%s\": read %d of %zu",
+                       pg_fatal("could not read file \"%s\": read %zd of %zu",
                                         ControlFilePath, r, sizeof(ControlFileData));
 #endif
        }
index 97eae2c1daba8c91c1f4ca94565e22fe5548feb9..4a9a687e8796df48bb78cbd1ba6268382d2e36e5 100644 (file)
@@ -382,9 +382,9 @@ extern void XLogReaderResetError(XLogReaderState *state);
 typedef struct WALReadError
 {
        int                     wre_errno;              /* errno set by the last pg_pread() */
-       int                     wre_off;                /* Offset we tried to read from. */
-       int                     wre_req;                /* Bytes requested to be read. */
-       int                     wre_read;               /* Bytes read by the last read(). */
+       uint32          wre_off;                /* Offset we tried to read from. */
+       size_t          wre_req;                /* Bytes requested to be read. */
+       ssize_t         wre_read;               /* Bytes read by the last read(). */
        WALOpenSegment wre_seg;         /* Segment we tried to read from. */
 } WALReadError;
 
index 12a32fcbaf37152caf228ef6c5bb478641ae4369..3014cae33ac1778d41c45d86833e15300116743a 100644 (file)
@@ -647,8 +647,8 @@ static Oid
 lo_import_internal(PGconn *conn, const char *filename, Oid oid)
 {
        int                     fd;
-       int                     nbytes,
-                               tmp;
+       ssize_t         nbytes;
+       int                     tmp;
        char            buf[LO_BUFSIZE];
        Oid                     lobjOid;
        int                     lobj;
index fefef1395b8ffe7d7850e8b1865eca7ec4213a1e..f73a0fcb10018e07b7b2c95e34edf0cfab4d8b0e 100644 (file)
@@ -36,8 +36,8 @@ importFile(PGconn *conn, char *filename)
        Oid                     lobjId;
        int                     lobj_fd;
        char            buf[BUFSIZE];
-       int                     nbytes,
-                               tmp;
+       ssize_t         nbytes;
+       int                     tmp;
        int                     fd;
 
        /*
@@ -79,7 +79,7 @@ pickout(PGconn *conn, Oid lobjId, int start, int len)
 {
        int                     lobj_fd;
        char       *buf;
-       int                     nbytes;
+       ssize_t         nbytes;
        int                     nread;
 
        lobj_fd = lo_open(conn, lobjId, INV_READ);
index 32404e59f5de61a5085535714be25860f429a9be..cecfa6836985a32076d2f9b50e0b59b7146d9895 100644 (file)
@@ -37,8 +37,8 @@ importFile(PGconn *conn, char *filename)
        Oid                     lobjId;
        int                     lobj_fd;
        char            buf[BUFSIZE];
-       int                     nbytes,
-                               tmp;
+       ssize_t         nbytes;
+       int                     tmp;
        int                     fd;
 
        /*