public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110322] New: Be more helpful when a varargs function is called in a wrong way
@ 2023-06-20 15:43 roland.illig at gmx dot de
  2023-06-20 16:34 ` [Bug c/110322] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: roland.illig at gmx dot de @ 2023-06-20 15:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110322

            Bug ID: 110322
           Summary: Be more helpful when a varargs function is called in a
                    wrong way
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roland.illig at gmx dot de
  Target Milestone: ---

~~~c
#include <stdarg.h>
#include <stdio.h>

static void __attribute__((__format__(__printf__, 1, 2)))
my_printf(const char *fmt, ...)
{
        va_list ap;

        va_start(ap, fmt);
        fprintf(stderr, fmt, ap);
        va_end(ap);
}

int
main(int argc, char **argv)
{
        my_printf("%d", 4);
        my_printf("%.*s\n", 5, "hello, world");
        return 0;
}
~~~

In the above program, I am accidentally trying to call fprintf with a va_list,
instead of the correct vfprintf. GCC warns:

sl.c:10:2: error: format not a string literal, argument types not checked
    [-Werror=format-nonliteral]
   10 |  fprintf(stderr, fmt, ap);
      |  ^~~~~~~

In this situation, where my only mistake was to forget the 'v' from the
function name, GCC should not complain that the format string is not a string
literal, but rather that I'm calling the wrong function.

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

end of thread, other threads:[~2023-06-21  6:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-20 15:43 [Bug c/110322] New: Be more helpful when a varargs function is called in a wrong way roland.illig at gmx dot de
2023-06-20 16:34 ` [Bug c/110322] " pinskia at gcc dot gnu.org
2023-06-20 16:34 ` pinskia at gcc dot gnu.org
2023-06-20 16:35 ` pinskia at gcc dot gnu.org
2023-06-21  6:35 ` egallager at gcc dot gnu.org
2023-06-21  6:58 ` xry111 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).