public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39438]  New: Can't compile a wrapper around strftime with -Werror=format-nonliteral
@ 2009-03-11 22:57 4tmuelle at informatik dot uni-hamburg dot de
  2009-03-12  9:40 ` [Bug c/39438] " rguenth at gcc dot gnu dot org
  2009-03-12  9:58 ` 4tmuelle at informatik dot uni-hamburg dot de
  0 siblings, 2 replies; 12+ messages in thread
From: 4tmuelle at informatik dot uni-hamburg dot de @ 2009-03-11 22:57 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4017 bytes --]

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;
} 



muelli@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
muelli@bigbox /tmp $ 


I raised this issue on gcc-help (Message-ID:
<49A96972.5060004@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


^ permalink raw reply	[flat|nested] 12+ messages in thread
[parent not found: <bug-39438-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2024-06-03  1:48 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-11 22:57 [Bug c/39438] New: Can't compile a wrapper around strftime with -Werror=format-nonliteral 4tmuelle at informatik dot uni-hamburg dot de
2009-03-12  9:40 ` [Bug c/39438] " rguenth at gcc dot gnu dot org
2009-03-12  9:58 ` 4tmuelle at informatik dot uni-hamburg dot de
     [not found] <bug-39438-4@http.gcc.gnu.org/bugzilla/>
2012-01-10 20:39 ` tss at iki dot fi
2014-05-10 16:47 ` hugh at mimosa dot com
2014-05-12 12:26 ` manu at gcc dot gnu.org
2014-05-12 14:58 ` hugh at mimosa dot com
2014-05-12 15:38 ` manu at gcc dot gnu.org
2014-05-12 15:52 ` manu at gcc dot gnu.org
2014-05-12 19:33 ` hugh at mimosa dot com
2015-02-27 16:43 ` manu at gcc dot gnu.org
2024-06-03  1:48 ` peter0x44 at disroot dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).