Remove some unnecessary casts in format arguments
authorPeter Eisentraut <peter@eisentraut.org>
Sun, 8 Aug 2021 20:05:42 +0000 (22:05 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Sun, 8 Aug 2021 20:08:07 +0000 (22:08 +0200)
We can use %zd or %zu directly, no need to cast to int.  Conversely,
some code was casting away from int when it could be using %d
directly.

src/backend/access/spgist/spgutils.c
src/backend/access/transam/xlogutils.c
src/backend/utils/adt/xml.c
src/bin/pg_basebackup/receivelog.c
src/bin/pg_waldump/pg_waldump.c

index 9ff280a2526badd0ac3e0c732eff148c4bf5ee32..03a9cd36e63356a29ccbdb8a2f1d3cbb76650f15 100644 (file)
@@ -1240,8 +1240,8 @@ SpGistPageAddNewItem(SpGistState *state, Page page, Item item, Size size,
                    *startOffset = offnum + 1;
            }
            else
-               elog(PANIC, "failed to add item of size %u to SPGiST index page",
-                    (int) size);
+               elog(PANIC, "failed to add item of size %zu to SPGiST index page",
+                    size);
 
            return offnum;
        }
@@ -1252,8 +1252,8 @@ SpGistPageAddNewItem(SpGistState *state, Page page, Item item, Size size,
                         InvalidOffsetNumber, false, false);
 
    if (offnum == InvalidOffsetNumber && !errorOK)
-       elog(ERROR, "failed to add item of size %u to SPGiST index page",
-            (int) size);
+       elog(ERROR, "failed to add item of size %zu to SPGiST index page",
+            size);
 
    return offnum;
 }
index b1702bc6bef41f8244792a72b11e8e0562273afd..88a1bfd9394aaa0513b69b98a662c5e834184788 100644 (file)
@@ -991,8 +991,8 @@ WALReadRaiseError(WALReadError *errinfo)
    {
        ereport(ERROR,
                (errcode(ERRCODE_DATA_CORRUPTED),
-                errmsg("could not read from log segment %s, offset %u: read %d of %zu",
+                errmsg("could not read from log segment %s, offset %u: read %d of %d",
                        fname, errinfo->wre_off, errinfo->wre_read,
-                       (Size) errinfo->wre_req)));
+                       errinfo->wre_req)));
    }
 }
index 3ae5cfac9e0f02c3c691278271c65ec6ab750df8..ba90187f8b891f2b258d7c3fe5f6cbb1bd09ceae 100644 (file)
@@ -959,8 +959,8 @@ pg_xml_init_library(void)
        if (sizeof(char) != sizeof(xmlChar))
            ereport(ERROR,
                    (errmsg("could not initialize XML library"),
-                    errdetail("libxml2 has incompatible char type: sizeof(char)=%u, sizeof(xmlChar)=%u.",
-                              (int) sizeof(char), (int) sizeof(xmlChar))));
+                    errdetail("libxml2 has incompatible char type: sizeof(char)=%zu, sizeof(xmlChar)=%zu.",
+                              sizeof(char), sizeof(xmlChar))));
 
 #ifdef USE_LIBXMLCONTEXT
        /* Set up libxml's memory allocation our way */
index 44cb5b36611df3284c626b018e4c4861a51809e0..ec53b6837e787e76440cec16e16fcf73ecd853e3 100644 (file)
@@ -150,10 +150,10 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
            /* if write didn't set errno, assume problem is no disk space */
            if (errno == 0)
                errno = ENOSPC;
-           pg_log_error(ngettext("write-ahead log file \"%s\" has %d byte, should be 0 or %d",
-                                 "write-ahead log file \"%s\" has %d bytes, should be 0 or %d",
+           pg_log_error(ngettext("write-ahead log file \"%s\" has %zd byte, should be 0 or %d",
+                                 "write-ahead log file \"%s\" has %zd bytes, should be 0 or %d",
                                  size),
-                        fn, (int) size, WalSegSz);
+                        fn, size, WalSegSz);
            pg_free(fn);
            return false;
        }
index 74664bef6a46b3b4f8c391fc0d72fdd5b2ad321c..1e3894b9c4550c958313a420e86007a2a3b474ce 100644 (file)
@@ -211,8 +211,8 @@ search_directory(const char *directory, const char *fname)
                fatal_error("could not read file \"%s\": %m",
                            fname);
            else
-               fatal_error("could not read file \"%s\": read %d of %zu",
-                           fname, r, (Size) XLOG_BLCKSZ);
+               fatal_error("could not read file \"%s\": read %d of %d",
+                           fname, r, XLOG_BLCKSZ);
        }
        close(fd);
        return true;
@@ -369,9 +369,9 @@ WALDumpReadPage(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen,
                        fname, errinfo.wre_off);
        }
        else
-           fatal_error("could not read from file %s, offset %u: read %d of %zu",
+           fatal_error("could not read from file %s, offset %u: read %d of %d",
                        fname, errinfo.wre_off, errinfo.wre_read,
-                       (Size) errinfo.wre_req);
+                       errinfo.wre_req);
    }
 
    return count;