public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "sworddragon2 at aol dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/55892] New: Bogus compiler warning Date: Mon, 07 Jan 2013 06:50:00 -0000 [thread overview] Message-ID: <bug-55892-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55892 Bug #: 55892 Summary: Bogus compiler warning Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: sworddragon2@aol.com Created attachment 29092 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29092 Example code In the attachments is the example file for this bug report. Compiling it with "gcc -O3 -Wall -Wextra -o /dev/null -pedantic test.c" will result in a warning: In file included from /usr/include/stdio.h:937:0, from test.c:2: In function 'fgets', inlined from 'main' at test.c:17:11: /usr/include/x86_64-linux-gnu/bits/stdio2.h:261:2: warning: call to '__fgets_chk_warn' declared with attribute warning: fgets called with bigger size than length of destination buffer [enabled by default] There are 2 potential errors on this behavior: - If the warning triggers on line 33 it should also be triggered on all 4 lines. - In this code the limit of fgets can never exceed a length of 8. The compiler thinks because read_limit can be 2147483647 (INT32_MAX) limit in fgets can it be too (which as already said can never happen in this code). Removing the 3 lines which assign INT32_MAX removes the compiler warning. I have a suggestion for a solution: - Like conditional return values the compiler could check if the code has a fixed construct which makes it possible to calculate if the limit will be exceeded (this would match on the example code and trigger no compiler warnings). If the code has a dynamic construct which makes it not possible to calculate if the limit would be exceeded a comiler warning is thrown.
next reply other threads:[~2013-01-07 6:50 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-01-07 6:50 sworddragon2 at aol dot com [this message] 2013-01-07 7:35 ` [Bug c/55892] " pinskia at gcc dot gnu.org 2013-01-07 8:01 ` sworddragon2 at aol dot com 2015-08-12 10:59 ` mpolacek 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-55892-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).