]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Make blkreftable API use size_t/ssize_t consistently
authorPeter Eisentraut <peter@eisentraut.org>
Mon, 13 Jul 2026 09:01:36 +0000 (11:01 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Mon, 13 Jul 2026 15:55:22 +0000 (17:55 +0200)
It was using int for the input and output length, where size_t or
ssize_t would be more appropriate.  It might not matter in practice,
but it makes the APIs consistent at all levels.

Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://www.postgresql.org/message-id/flat/f9aab072-0078-49e4-ab93-3b08086a4406@eisentraut.org

src/backend/backup/walsummary.c
src/bin/pg_walsummary/pg_walsummary.c
src/common/blkreftable.c
src/include/backup/walsummary.h
src/include/common/blkreftable.h

index 48b7bd8c5211955d8245cf800b6d10a0e541e308..3d044a92417ad1f74e7e10f0ea3ff8bcffa11857 100644 (file)
@@ -269,11 +269,11 @@ IsWalSummaryFilename(char *filename)
 /*
  * Data read callback for use with CreateBlockRefTableReader.
  */
-int
-ReadWalSummary(void *wal_summary_io, void *data, int length)
+size_t
+ReadWalSummary(void *wal_summary_io, void *data, size_t length)
 {
        WalSummaryIO *io = wal_summary_io;
-       int                     nbytes;
+       ssize_t         nbytes;
 
        nbytes = FileRead(io->file, data, length, io->filepos,
                                          WAIT_EVENT_WAL_SUMMARY_READ);
@@ -290,11 +290,11 @@ ReadWalSummary(void *wal_summary_io, void *data, int length)
 /*
  * Data write callback for use with WriteBlockRefTable.
  */
-int
-WriteWalSummary(void *wal_summary_io, void *data, int length)
+size_t
+WriteWalSummary(void *wal_summary_io, void *data, size_t length)
 {
        WalSummaryIO *io = wal_summary_io;
-       int                     nbytes;
+       ssize_t         nbytes;
 
        nbytes = FileWrite(io->file, data, length, io->filepos,
                                           WAIT_EVENT_WAL_SUMMARY_WRITE);
@@ -306,7 +306,7 @@ WriteWalSummary(void *wal_summary_io, void *data, int length)
        if (nbytes != length)
                ereport(ERROR,
                                (errcode_for_file_access(),
-                                errmsg("could not write file \"%s\": wrote only %d of %d bytes at offset %lld",
+                                errmsg("could not write file \"%s\": wrote only %zd of %zu bytes at offset %lld",
                                                FilePathName(io->file), nbytes,
                                                length, (long long) io->filepos),
                                 errhint("Check free disk space.")));
index c3e98ffe55edfec3d64dea0e0758e86a65721481..ad674b7646a458814e04ea13572d22141ea09b07 100644 (file)
@@ -41,8 +41,8 @@ static void dump_one_relation(ws_options *opt, RelFileLocator *rlocator,
                                                          BlockRefTableReader *reader);
 static void help(const char *progname);
 static int     compare_block_numbers(const void *a, const void *b);
-static int     walsummary_read_callback(void *callback_arg, void *data,
-                                                                        int length);
+static size_t walsummary_read_callback(void *callback_arg, void *data,
+                                                                          size_t length);
 static void walsummary_error_callback(void *callback_arg, char *fmt, ...) pg_attribute_printf(2, 3);
 
 /*
@@ -241,11 +241,11 @@ walsummary_error_callback(void *callback_arg, char *fmt, ...)
 /*
  * Read callback.
  */
-int
-walsummary_read_callback(void *callback_arg, void *data, int length)
+size_t
+walsummary_read_callback(void *callback_arg, void *data, size_t length)
 {
        ws_file_info *ws = callback_arg;
-       int                     rc;
+       ssize_t         rc;
 
        if ((rc = read(ws->fd, data, length)) < 0)
                pg_fatal("could not read file \"%s\": %m", ws->filename);
index 2bb91e391282161cf6a9e886ecde816566e83d36..a4c72159f94035ce5cd456e4d75e397d666852e4 100644 (file)
@@ -173,8 +173,8 @@ typedef struct BlockRefTableBuffer
        io_callback_fn io_callback;
        void       *io_callback_arg;
        char            data[BUFSIZE];
-       int                     used;
-       int                     cursor;
+       size_t          used;
+       size_t          cursor;
        pg_crc32c       crc;
 } BlockRefTableBuffer;
 
@@ -223,9 +223,9 @@ struct BlockRefTableWriter
 static int     BlockRefTableComparator(const void *a, const void *b);
 static void BlockRefTableFlush(BlockRefTableBuffer *buffer);
 static void BlockRefTableRead(BlockRefTableReader *reader, void *data,
-                                                         int length);
+                                                         size_t length);
 static void BlockRefTableWrite(BlockRefTableBuffer *buffer, void *data,
-                                                          int length);
+                                                          size_t length);
 static void BlockRefTableFileTerminate(BlockRefTableBuffer *buffer);
 
 /*
@@ -1206,7 +1206,7 @@ BlockRefTableFlush(BlockRefTableBuffer *buffer)
  * buffered but not yet actually returned).
  */
 static void
-BlockRefTableRead(BlockRefTableReader *reader, void *data, int length)
+BlockRefTableRead(BlockRefTableReader *reader, void *data, size_t length)
 {
        BlockRefTableBuffer *buffer = &reader->buffer;
 
@@ -1219,7 +1219,7 @@ BlockRefTableRead(BlockRefTableReader *reader, void *data, int length)
                         * If any buffered data is available, use that to satisfy as much
                         * of the request as possible.
                         */
-                       int                     bytes_to_copy = Min(length, buffer->used - buffer->cursor);
+                       size_t          bytes_to_copy = Min(length, buffer->used - buffer->cursor);
 
                        memcpy(data, &buffer->data[buffer->cursor], bytes_to_copy);
                        COMP_CRC32C(buffer->crc, &buffer->data[buffer->cursor],
@@ -1234,7 +1234,7 @@ BlockRefTableRead(BlockRefTableReader *reader, void *data, int length)
                         * If the request length is long, read directly into caller's
                         * buffer.
                         */
-                       int                     bytes_read;
+                       size_t          bytes_read;
 
                        bytes_read = buffer->io_callback(buffer->io_callback_arg,
                                                                                         data, length);
@@ -1271,7 +1271,7 @@ BlockRefTableRead(BlockRefTableReader *reader, void *data, int length)
  * and update the running CRC calculation for that data.
  */
 static void
-BlockRefTableWrite(BlockRefTableBuffer *buffer, void *data, int length)
+BlockRefTableWrite(BlockRefTableBuffer *buffer, void *data, size_t length)
 {
        /* Update running CRC calculation. */
        COMP_CRC32C(buffer->crc, data, length);
index 093b42df473fd41a26b4a21c06268bcb11afda34..748c679de0356e532b49b5ad2fbec2b80d8a64c2 100644 (file)
@@ -42,8 +42,8 @@ extern File OpenWalSummaryFile(WalSummaryFile *ws, bool missing_ok);
 extern void RemoveWalSummaryIfOlderThan(WalSummaryFile *ws,
                                                                                time_t cutoff_time);
 
-extern int     ReadWalSummary(void *wal_summary_io, void *data, int length);
-extern int     WriteWalSummary(void *wal_summary_io, void *data, int length);
+extern size_t ReadWalSummary(void *wal_summary_io, void *data, size_t length);
+extern size_t WriteWalSummary(void *wal_summary_io, void *data, size_t length);
 extern void ReportWalSummaryError(void *callback_arg, char *fmt, ...) pg_attribute_printf(2, 3);
 
 #endif                                                 /* WALSUMMARY_H */
index 42b11b0a2b10a5d01286cae642a196fe655fea65..fbb8af4d6e5e5632cdc47a101edba90da83f50de 100644 (file)
@@ -43,7 +43,7 @@ typedef struct BlockRefTableWriter BlockRefTableWriter;
  *
  * report_error_fn should not return.
  */
-typedef int (*io_callback_fn) (void *callback_arg, void *data, int length);
+typedef size_t (*io_callback_fn) (void *callback_arg, void *data, size_t length);
 typedef void (*report_error_fn) (void *callback_arg, char *msg, ...) pg_attribute_printf(2, 3);