public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96951] New: strncpy truncation warning does not recognize truncation check
@ 2020-09-07  9:54 fw at gcc dot gnu.org
  2020-09-07 10:04 ` [Bug tree-optimization/96951] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: fw at gcc dot gnu.org @ 2020-09-07  9:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

end of thread, other threads:[~2020-09-08 12:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-07  9:54 [Bug tree-optimization/96951] New: strncpy truncation warning does not recognize truncation check fw at gcc dot gnu.org
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

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).