I basically have a wrapper around strftime() and compilation with -Werror=format-nonliteral fails when the wrapper wants to call strftime, because "format not a string literal, format string not checked".
The code in question looks like this: #include<time.h> #include<stdio.h> #define SIZE 256 size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) { size_t ret; ret = strftime(s, max, fmt, tm); return ret; } int main () { char s[SIZE]; time_t curtime; struct tm* loctime; curtime = time(NULL); loctime = localtime (&curtime); my_strftime(s, SIZE, "Hello %A", loctime); printf("%s", s); return 0; } mue...@bigbox /tmp $ gcc -v -save-temp -Wformat -Wformat-nonliteral -Werror=format-nonliteral -o mystrftime{,.c} Using built-in specs. gcc: unrecognized option '-save-temp' Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-cpu=generic --build=x86_64-redhat-linux Thread model: posix gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temp' '-Wformat' '-Wformat-nonliteral' '-Werror=format-nonliteral' '-o' 'mystrftime' '-mtune=generic' /usr/libexec/gcc/x86_64-redhat-linux/4.3.2/cc1 -quiet -v mystrftime.c -quiet -dumpbase mystrftime.c -mtune=generic -auxbase mystrftime -Wformat -Wformat-nonliteral -Werror=format-nonliteral -version -o /tmp/ccznk3Wo.s ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.3.2/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.3.2/../../../../x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/lib/gcc/x86_64-redhat-linux/4.3.2/include /usr/include End of search list. GNU C (GCC) version 4.3.2 20081105 (Red Hat 4.3.2-7) (x86_64-redhat-linux) compiled by GNU C version 4.3.2 20081105 (Red Hat 4.3.2-7), GMP version 4.2.2, MPFR version 2.3.2. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: c99c7b3dc8e919a4b394102437269a84 mystrftime.c: In function my_strftime: mystrftime.c:14: error: format not a string literal, format string not checked mue...@bigbox /tmp $ I raised this issue on gcc-help (Message-ID: <49a96972.5060...@informatik.uni-hamburg.de>) and got the tip to use __attribute__(( format(strftime, 3, 0) )) but it doesn't work. I think I want to make gcc * know that the wrapper is not responsible for the format string and thus the call to strftime is allowed * pass the responsibility up to the callers and thus check whether they call the wrapper with "good" strings. but it doesn't seem possible. I hope to have all needed information included. I can't, however, fulfil the request from http://gcc.gnu.org/bugs.html to attach *.*i* files, because there are none. Also, I searched the bugzilla for "format-nonliteral" and found nothing related to this issue. I thus think it hasn't been filed yet. -- Summary: Can't compile a wrapper around strftime with - Werror=format-nonliteral Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: 4tmuelle at informatik dot uni-hamburg dot de http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39438