public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102875] New: __builtin_strncpy output may be truncated copying bytes from a string of length
@ 2021-10-21 11:16 johnnymarler at gmail dot com
2021-10-21 12:49 ` [Bug c/102875] " rguenth at gcc dot gnu.org
2021-10-21 19:10 ` johnnymarler at gmail dot com
0 siblings, 2 replies; 3+ messages in thread
From: johnnymarler at gmail dot com @ 2021-10-21 11:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102875
Bug ID: 102875
Summary: __builtin_strncpy output may be truncated copying
bytes from a string of length
Product: gcc
Version: 9.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: johnnymarler at gmail dot com
Target Milestone: ---
GCC Version: 9.2.0
System: NixOS
$ gcc -v
Using built-in specs.
COLLECT_GCC=/nix/store/b3zsk4ihlpiimv3vff86bb5bxghgdzb9-gcc-9.2.0/bin/gcc
COLLECT_LTO_WRAPPER=/nix/store/b3zsk4ihlpiimv3vff86bb5bxghgdzb9-gcc-9.2.0/libexec/gcc/x86_64-unknown-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with:
Thread model: posix
gcc version 9.2.0 (GCC)
How to reproduce:
wtf.c
------------------------------
#include <string.h>
// value of 2 works???
//#define COPY_COUNT 2
// values >3 don't work
#define COPY_COUNT 3
typedef struct {
// NOTE: these padding values don't fix it
//int something_to_pad_between_elements_1;
char array[100];
//int something_to_pad_between_elements_2;
} StringBuf;
int main()
{
StringBuf a[COPY_COUNT];
StringBuf b[COPY_COUNT];
for (unsigned i = 0; i < COPY_COUNT; i++) {
strncpy(a[i].array, b[i].array, 100);
}
}
------------------------------
$ gcc -Wall wtf.c
In file included from
/nix/store/fwpn2f7a4iqszyydw7ag61zlnp6xk5d3-glibc-2.30-dev/include/string.h:494,
from wtf.c:1:
In function ‘strncpy’,
inlined from ‘main’ at wtf.c:21:5:
/nix/store/fwpn2f7a4iqszyydw7ag61zlnp6xk5d3-glibc-2.30-dev/include/bits/string_fortified.h:106:10:
warning: ‘__builtin_strncpy’ output may be truncated copying 100 bytes from a
string of length 299 [-Wstringop-truncation]
106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos
(__dest));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expected Results:
This example is expected to compile with no issues.
Actual Results:
The compiler erroneously warns about a truncated strcpy when no such truncation
occurs.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/102875] __builtin_strncpy output may be truncated copying bytes from a string of length
2021-10-21 11:16 [Bug c/102875] New: __builtin_strncpy output may be truncated copying bytes from a string of length johnnymarler at gmail dot com
@ 2021-10-21 12:49 ` rguenth at gcc dot gnu.org
2021-10-21 19:10 ` johnnymarler at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-21 12:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102875
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Known to fail| |10.3.0, 11.2.0, 9.4.1
Last reconfirmed| |2021-10-21
Keywords| |diagnostic
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed with the branch head, but you need -O2 -Wall to reproduce. It seems
fixed in GCC 10 and GCC 11.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/102875] __builtin_strncpy output may be truncated copying bytes from a string of length
2021-10-21 11:16 [Bug c/102875] New: __builtin_strncpy output may be truncated copying bytes from a string of length johnnymarler at gmail dot com
2021-10-21 12:49 ` [Bug c/102875] " rguenth at gcc dot gnu.org
@ 2021-10-21 19:10 ` johnnymarler at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: johnnymarler at gmail dot com @ 2021-10-21 19:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102875
Jonathan Marler <johnnymarler at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
--- Comment #2 from Jonathan Marler <johnnymarler at gmail dot com> ---
I confirmed this is fixed in 10.3.0.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-21 19:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-21 11:16 [Bug c/102875] New: __builtin_strncpy output may be truncated copying bytes from a string of length johnnymarler at gmail dot com
2021-10-21 12:49 ` [Bug c/102875] " rguenth at gcc dot gnu.org
2021-10-21 19:10 ` johnnymarler at gmail dot com
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).