Skip to contentSkip to conversation

Warnings fixes for building with clang

PATCH New Tom Stellard 1 participant 3 messages Apr 24, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

Here are a few patches to fix warnings caught while building with clang.

-Tom

#1 lore raw

PATCH 1/2 Fix -Wformat-nonliteral warning

xcommon.c:101:24: error: format string is not a string literal [-Werror,-Wformat-nonliteral]

     vfprintf (stderr, fmt2, args);
                       ^~~~
---
 support/nfs/xcommon.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
support/nfs/xcommon.c +2 -4
index 3989f0bc..1d04dd11 100644
@@ -94,13 +94,11 @@ xstrconcat4 (const char *s, const char *t, const char *u, const char *v) {
 void
 nfs_error (const char *fmt, ...) {
      va_list args;
-     char *fmt2;
 
-     fmt2 = xstrconcat2 (fmt, "\n");
      va_start (args, fmt);
-     vfprintf (stderr, fmt2, args);
+     vfprintf (stderr, fmt, args);
+     fprintf (stderr, "\n");
      va_end (args);
-     free (fmt2);
 }
 
 /* Make a canonical pathname from PATH.  Returns a freshly malloced string.
Signature · 1 line
2.25.3
#2 lore raw

PATCH 2/2 Use format attribute to silence -Wformat-nonliteral warnings

In reply to Tom Stellard

This will also cause the compiler to add checks to ensure the arguments are consistent with the printf format.

---
 support/nfsidmap/libnfsidmap.c | 2 +-
 utils/gssd/err_util.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
support/nfsidmap/libnfsidmap.c +1 -1
index bce448cf..5d551e4f 100644
@@ -94,7 +94,7 @@ gid_t nobody_gid = (gid_t)-1;
 #endif
 
 /* Default logging fuction */
-static void default_logger(const char *fmt, ...)
+__attribute__ ((format (printf, 1, 2))) static void default_logger(const char *fmt, ...)
 {
 	va_list vp;
 
utils/gssd/err_util.c +1 -1
index 2b1132ac..7179cc02 100644
@@ -50,7 +50,7 @@ void initerr(char *progname, int set_verbosity, int set_fg)
 }
 
 
-void printerr(int priority, char *format, ...)
+__attribute__ ((format (printf, 2, 3))) void printerr(int priority, char *format, ...)
 {
 	va_list args;
 
Signature · 1 line
2.25.3