public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "nvinson234+gcc-bugs at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/109851] New: False positive va_arg when iterating through format string with for-loop Date: Sat, 13 May 2023 23:15:23 +0000 [thread overview] Message-ID: <bug-109851-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109851 Bug ID: 109851 Summary: False positive va_arg when iterating through format string with for-loop Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: nvinson234+gcc-bugs at gmail dot com Target Milestone: --- Created attachment 55081 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55081&action=edit analzyer warning output When compiling the following code: #include<stdio.h> #include<stdarg.h> #include<string.h> void foo(char *fmt, ...) { int i = 0; char c; va_list ap; va_start(ap, fmt); for (i = 0; (c = fmt[i]) != 0; i++) { c = fmt[i]; if (c == '%') { printf("Saw %%"); } if (c == 'd') { i = va_arg(ap, int); } } va_end(ap); } int main(int argc, char **argv) { foo("%s.lt", argv[0]); return 0; } with the command: gcc -O2 -fanalyzer test.c The analyzer gives the warning: test.c:17:15: warning: ‘va_arg’ expected ‘int’ but received ‘char *’ for variadic argument 1 of ‘ap’ However, the condition "c == 'd'" is never true and va_arg() is never called. This is a reduced case based on the lemon_vsnprintf() code found in sqlite-3.41.2'a tool/lemon.c. Full warning output attached.
next reply other threads:[~2023-05-13 23:15 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-13 23:15 nvinson234+gcc-bugs at gmail dot com [this message] 2024-02-16 19:39 ` [Bug analyzer/109851] [13/14 Regression] " dmalcolm at gcc dot gnu.org 2024-03-04 13:00 ` rguenth at gcc dot gnu.org 2024-03-08 15:36 ` law at gcc dot gnu.org 2024-05-21 9:15 ` [Bug analyzer/109851] [13/14/15 " jakub 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-109851-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).