public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "fw at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/96951] New: strncpy truncation warning does not recognize truncation check Date: Mon, 07 Sep 2020 09:54:57 +0000 [thread overview] Message-ID: <bug-96951-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96951 Bug ID: 96951 Summary: strncpy truncation warning does not recognize truncation check Product: gcc Version: 10.2.1 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: fw at gcc dot gnu.org Target Milestone: --- This code example produces a warning: #include <string.h> struct buffer { char string[10]; }; int f (struct buffer *p, const char *s) { strncpy (p->string, s, sizeof (p->string)); if (p->string[sizeof (p->string) - 1] != '\0') return -1; return 0; } t.c: In function ‘f’: t.c:10:3: warning: ‘strncpy’ specified bound 10 equals destination size [-Wstringop-truncation] 10 | strncpy (p->string, s, sizeof (p->string)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ There is an explicit truncation check, however, so the warning does not apply. Suggested by Kim Barrett here: https://mail.openjdk.java.net/pipermail/hotspot-dev/2020-September/042890.html -- Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn, Commercial register: Amtsgericht Muenchen, HRB 153243, Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
next reply other threads:[~2020-09-07 9:54 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-09-07 9:54 fw at gcc dot gnu.org [this message] 2020-09-07 10:04 ` [Bug tree-optimization/96951] " jakub at gcc dot gnu.org 2020-09-07 10:10 ` fw at gcc dot gnu.org 2020-09-07 17:27 ` msebor at gcc dot gnu.org 2020-09-08 12:36 ` fw at gcc dot gnu.org 2020-09-08 12:38 ` kab at acm dot 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-96951-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).