Clean up minor inconsistencies in pg_attribute_printf() usage.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 16 Sep 2022 15:10:48 +0000 (11:10 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 16 Sep 2022 15:10:48 +0000 (11:10 -0400)
For some reason we'd never decorated pg_v*printf() with
pg_attribute_printf() annotations.  There is a convention for
how to label va_list-using printf functions (write zero for the
second argument), and we use that liberally elsewhere in the
code, but these core functions lacked it.  It's not clear how
much useful checking the compiler can do for calls of these,
but we might as well add the annotations.

Also, sync win32security.c's log_error() with our normal convention
that pg_attribute_printf must be attached to a function's declaration
not definition.  Apparently this file is only compiled with compilers
that aren't picky about that, but still it'd be better to be
consistent.

No back-patch since there's little reason to think we would catch
anything.

Discussion: https://postgr.es/m/3492412.1663283395@sss.pgh.pa.us

src/include/port.h
src/port/win32security.c

index ce5da0534e87ba74579c6be19f014baf259e4444..fe48618df7b0880cfe5b0fe9601db7420f6f93bd 100644 (file)
@@ -204,13 +204,13 @@ extern unsigned char pg_ascii_tolower(unsigned char ch);
 #undef printf
 #endif
 
-extern int     pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
+extern int     pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args) pg_attribute_printf(3, 0);
 extern int     pg_snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3, 4);
-extern int     pg_vsprintf(char *str, const char *fmt, va_list args);
+extern int     pg_vsprintf(char *str, const char *fmt, va_list args) pg_attribute_printf(2, 0);
 extern int     pg_sprintf(char *str, const char *fmt,...) pg_attribute_printf(2, 3);
-extern int     pg_vfprintf(FILE *stream, const char *fmt, va_list args);
+extern int     pg_vfprintf(FILE *stream, const char *fmt, va_list args) pg_attribute_printf(2, 0);
 extern int     pg_fprintf(FILE *stream, const char *fmt,...) pg_attribute_printf(2, 3);
-extern int     pg_vprintf(const char *fmt, va_list args);
+extern int     pg_vprintf(const char *fmt, va_list args) pg_attribute_printf(1, 0);
 extern int     pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
 
 /*
index 1235199f2fbc938cfc066259f0d9199f16a13978..281244a34fb7bfd1ccf71d4cd0d9b4d19f1930b6 100644 (file)
 #include "postgres_fe.h"
 #endif
 
+static void log_error(const char *fmt,...) pg_attribute_printf(1, 2);
+
 
 /*
  * Utility wrapper for frontend and backend when reporting an error
  * message.
  */
-static
-pg_attribute_printf(1, 2)
-void
+static void
 log_error(const char *fmt,...)
 {
        va_list         ap;