public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/60194] New: -Wformat should also warn when using %d (instead of %u) for unsigned arguments
@ 2014-02-14 10:48 burnus at gcc dot gnu.org
  2014-02-14 12:27 ` [Bug c/60194] " burnus at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2014-02-14 10:48 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60194

            Bug ID: 60194
           Summary: -Wformat should also warn when using %d (instead of
                    %u) for unsigned arguments
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org

cppcheck has the following warning:

(warning) %d in format string (no. 1) requires 'int' but the argument type is
'unsigned int'

I think it would be useful to have the same warning with -Wformat. [One can
argue whether the warning should be always printed with -Wformat[=1] or only
with -Wformat=2 (+ -Wformat-unsigned).]


And of course also the other way round, e.g. using "%lu" or "%lz" with an
argument which is (signed) "long".


Example:

#include <stdio.h>
#include <limits.h>

void foo(unsigned i) {
  printf("%d\n", i);
}

int main() {
  foo(UINT_MAX);
  return 0;
}


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-04-11 22:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-14 10:48 [Bug c/60194] New: -Wformat should also warn when using %d (instead of %u) for unsigned arguments burnus at gcc dot gnu.org
2014-02-14 12:27 ` [Bug c/60194] " burnus at gcc dot gnu.org
2014-02-18 16:18 ` burnus at gcc dot gnu.org
2014-04-11 22:44 ` burnus at gcc dot gnu.org
2014-04-11 22:49 ` burnus at gcc dot gnu.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).