Avoid non-constant format string argument to fprintf().
authorHeikki Linnakangas <[email protected]>
Tue, 18 Aug 2020 10:13:09 +0000 (13:13 +0300)
committerHeikki Linnakangas <[email protected]>
Tue, 18 Aug 2020 10:13:28 +0000 (13:13 +0300)
As Tom Lane pointed out, it could defeat the compiler's printf() format
string verification.

Backpatch to v12, like that patch that introduced it.

Discussion: https://www.postgresql.org/message-id/1069283.1597672779%40sss.pgh.pa.us

src/bin/pg_basebackup/pg_basebackup.c
src/bin/pg_checksums/pg_checksums.c
src/bin/pg_rewind/pg_rewind.c

index 54bf864efde0695e494ab7f7e9c98a531df5942e..ac07a0ef009366ebcac9234888dc7af2a86f199d 100644 (file)
@@ -801,7 +801,7 @@ progress_report(int tablespacenum, const char *filename,
     * Stay on the same line if reporting to a terminal and we're not done
     * yet.
     */
-   fprintf(stderr, (!finished && isatty(fileno(stderr))) ? "\r" : "\n");
+   fputc((!finished && isatty(fileno(stderr))) ? '\r' : '\n', stderr);
 }
 
 static int32
index c4db327a673660d5c53e50160f19de4b60ad7d9b..4444d040640eb1c6fa9e730043d0bef8a6f4fcb0 100644 (file)
@@ -165,7 +165,7 @@ progress_report(bool finished)
     * Stay on the same line if reporting to a terminal and we're not done
     * yet.
     */
-   fprintf(stderr, (!finished && isatty(fileno(stderr))) ? "\r" : "\n");
+   fputc((!finished && isatty(fileno(stderr))) ? '\r' : '\n', stderr);
 }
 
 static bool
index 59c8695b6bda4eeeab8ea0f317b83ab21388790f..3f42ea6627461653d20a4afa7ed4b9269fbbfa9f 100644 (file)
@@ -505,7 +505,7 @@ progress_report(bool finished)
     * Stay on the same line if reporting to a terminal and we're not done
     * yet.
     */
-   fprintf(stderr, (!finished && isatty(fileno(stderr))) ? "\r" : "\n");
+   fputc((!finished && isatty(fileno(stderr))) ? '\r' : '\n', stderr);
 }
 
 /*