From 7475e957b6cef4c36a2cbed39ebfd9b78b710868 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 13 Nov 2026 10:58:53 +0100 Subject: [PATCH 4/5] Disable some -Wformat-nonliteral warnings via pragmas This is for cases that are not easily fixed, because we really want a non-literal format string. Also in some cases it's easier to disable this for imported code that we don't want to mess with too hard. TODO: disable pragmas in elog.c for non-GCC XXX: maybe package all of this up into reusable macros --- src/backend/utils/error/elog.c | 3 +++ src/bin/psql/tab-complete.in.c | 7 +++++++ src/interfaces/ecpg/pgtypeslib/timestamp.c | 7 +++++++ src/port/snprintf.c | 8 ++++++++ src/timezone/strftime.c | 7 +++++++ src/timezone/zic.c | 7 +++++++ 6 files changed, 39 insertions(+) diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index e215ed053ff..00173d32a37 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -1074,7 +1074,10 @@ errcode_for_socket_access(void) int needed; \ errno = edata->saved_errno; \ va_start(args, n); \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") \ needed = appendStringInfoVA(&buf, fmt, args); \ + _Pragma("GCC diagnostic pop") \ va_end(args); \ if (needed == 0) \ break; \ diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index 96de78cd087..add85fc1dc4 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -6126,9 +6126,16 @@ _complete_from_query(const char *simple_query, { Assert(simple_query); /* simple_query is an sprintf-style format string */ +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif appendPQExpBuffer(&query_buffer, simple_query, e_object_like, e_ref_object, e_ref_schema); +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif } /* Limit the number of records in the result */ diff --git a/src/interfaces/ecpg/pgtypeslib/timestamp.c b/src/interfaces/ecpg/pgtypeslib/timestamp.c index 0d8ceaa5cce..001e94e4f24 100644 --- a/src/interfaces/ecpg/pgtypeslib/timestamp.c +++ b/src/interfaces/ecpg/pgtypeslib/timestamp.c @@ -397,7 +397,14 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm *tm, * strftime's month is 0 based, ours is 1 based */ tm->tm_mon -= 1; +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif i = strftime(q, *pstr_len, tmp, tm); +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif if (i == 0) return -1; while (*q) diff --git a/src/port/snprintf.c b/src/port/snprintf.c index 2189ebfe399..52345c97ed3 100644 --- a/src/port/snprintf.c +++ b/src/port/snprintf.c @@ -35,6 +35,14 @@ #include +/* + * This file contains numerous violations of this warning, which is in the + * nature of what it does. So just disabling it globally is simplest. + */ +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif + /* * We used to use the platform's NL_ARGMAX here, but that's a bad idea, * first because the point of this module is to remove platform dependencies diff --git a/src/timezone/strftime.c b/src/timezone/strftime.c index 9c959f0119a..c50a844cad6 100644 --- a/src/timezone/strftime.c +++ b/src/timezone/strftime.c @@ -522,7 +522,14 @@ _conv(int n, const char *format, char *pt, const char *ptlim) { char buf[INT_STRLEN_MAXIMUM(int) + 1]; +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif sprintf(buf, format, n); +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif return _add(buf, pt, ptlim); } diff --git a/src/timezone/zic.c b/src/timezone/zic.c index a1256ca49c2..9614025012f 100644 --- a/src/timezone/zic.c +++ b/src/timezone/zic.c @@ -10,6 +10,13 @@ #include "postgres_fe.h" +/* + * Disabled for the whole file, to keep upstream merges simpler. + */ +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif + /* * Disable some warnings on MSVC. See also * . -- 2.56.0