public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/94741] New: stringop-truncation is triggered or not depending on surrounding members
@ 2020-04-24 7:13 danregister at poczta dot fm
2020-04-24 7:23 ` [Bug other/94741] " danregister at poczta dot fm
2020-04-24 7:45 ` rguenth at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: danregister at poczta dot fm @ 2020-04-24 7:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94741
Bug ID: 94741
Summary: stringop-truncation is triggered or not depending on
surrounding members
Product: gcc
Version: 9.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: other
Assignee: unassigned at gcc dot gnu.org
Reporter: danregister at poczta dot fm
Target Milestone: ---
The example code compiled with "-Wall -Werror -O2" gives:
main.cpp: In constructor ‘S3::S3(const char*)’:
main.cpp:26:22: error: 'char* __builtin_strncpy(char*, const char*, long
unsigned int)' specified bound 5 equals destination size
[-Werror=stringop-truncation]
26 | __builtin_strncpy(a_, a, kMaxLen);
It complains only about S3 while it should complain about all of them.
The example code:
constexpr auto kMaxLen = 5;
struct S1 { // just array
S1(const char* a);
char a_[kMaxLen];
};
S1::S1(const char* a) {
__builtin_strncpy(a_, a, kMaxLen);
}
struct S2 { // int member before array
S2(const char* a);
int n_;
char a_[kMaxLen];
};
S2::S2(const char* a) {
__builtin_strncpy(a_, a, kMaxLen);
}
struct S3 { // int member after array
S3(const char* a);
char a_[kMaxLen];
int n_;
};
S3::S3(const char* a) {
__builtin_strncpy(a_, a, kMaxLen);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-24 7:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-24 7:13 [Bug other/94741] New: stringop-truncation is triggered or not depending on surrounding members danregister at poczta dot fm
2020-04-24 7:23 ` [Bug other/94741] " danregister at poczta dot fm
2020-04-24 7:45 ` rguenth at gcc dot gnu.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).