public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "roland.illig at gmx dot de" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/110322] New: Be more helpful when a varargs function is called in a wrong way Date: Tue, 20 Jun 2023 15:43:12 +0000 [thread overview] Message-ID: <bug-110322-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2023-06-20 15:43 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-06-20 15:43 roland.illig at gmx dot de [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-110322-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).