This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/84397] New: missing -Wstringop-truncation on strncpy into a multidimensional array
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 15 Feb 2018 00:27:22 +0000
- Subject: [Bug tree-optimization/84397] New: missing -Wstringop-truncation on strncpy into a multidimensional array
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84397
Bug ID: 84397
Summary: missing -Wstringop-truncation on strncpy into a
multidimensional array
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
The -Wstringop-truncation detects the potential string truncation in the first
strncpy call below but fails to detect the similar problem in the second call.
$ cat a.c && gcc -O2 -S -Wall a.c
char a[2][7];
void f0 (const char *s)
{
__builtin_strncpy (a[0], s, sizeof a[0]); // missing -Wstringop-truncation
}
void f1 (const char *s)
{
__builtin_strncpy (a[1], s, sizeof a[1]); // -Wstringop-truncation (good)
}
void fi (const char *s, int i)
{
__builtin_strncpy (a[i], s, sizeof a[i]); // missing -Wstringop-truncation
}
a.c: In function ‘f1’:
a.c:10:3: warning: ‘__builtin_strncpy’ specified bound 7 equals destination
size [-Wstringop-truncation]
__builtin_strncpy (a[1], s, sizeof a[1]); // -Wstringop-truncation (good)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~