Skip to contentSkip to conversation

avoid format-mismatch warnings on x86_64

linux-lvm Jim Meyering 1 participant 1 message Apr 26, 2007

lore
Share & tools
lore
#0 lore raw

Building from cvs, with an added -Wformat-security option in CFLAGS, I got two warnings:

format_text/export.c:163: warning: format not a string literal and no format arguments format_text/export.c:179: warning: format not a string literal and no format arguments

The following patch fixes those and adds the option to make.tmpl.in.

2007-04-26 Jim Meyering <[email protected]>

* lib/format_text/export.c (_out_with_comment_file): Avoid using a non-literal fprintf format string. Instead, use fputs.

Index: lib/format_text/export.c
===================================================================
RCS file: /cvs/lvm2/LVM2/lib/format_text/export.c,v retrieving revision 1.54

format_text/export.c +2 -2
diff -u -p -r1.54 export.c
@@ -160,7 +160,7 @@ static int _out_with_comment_file(struct
 	for (i = 0; i < f->indent; i++)
 		white_space[i] = '\t';
 	white_space[i] = '\0';
-	fprintf(f->data.fp, white_space);
+	fputs(white_space, f->data.fp);
 	i = vfprintf(f->data.fp, fmt, ap);
 
 	if (comment) {
@@ -176,7 +176,7 @@ static int _out_with_comment_file(struct
 
 		while (++i < COMMENT_TAB);
 
-		fprintf(f->data.fp, comment);
+		fputs(comment, f->data.fp);
 	}
 	fputc('\n', f->data.fp);
 

Index: make.tmpl.in
===================================================================
RCS file: /cvs/lvm2/LVM2/make.tmpl.in,v
retrieving revision 1.47

make.tmpl.in +1 -1
diff -u -p -r1.47 make.tmpl.in
@@ -56,7 +56,7 @@ endif
 
 .SUFFIXES: .c .d .o .so .a .po .pot .mo .dylib
 
-CFLAGS += -fPIC -Wall -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -Wmissing-noreturn
+CFLAGS += -fPIC -Wall -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -Wmissing-noreturn -Wformat-security
 
 #CFLAGS += -W -Wconversion -Wpointer-arith -Wredundant-decls -Wbad-function-cast -Wcast-qual
 #CFLAGS += -pedantic -std=gnu99