This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/83373] False positive reported by -Wstringop-overflow


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83373

--- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> ---
GCC treats the last member array of a [sub]object as a flexible array member
only if it doesn't know the size of the whole object (the subobject can be a
member of a larger struct or an element of an array).  When it knows that the
[sub]object is, in fact, the whole object, it treats the array as an ordinary
one.  In that case the optimization kicks in and the warning is avoided.

With that, since in your example in comment #6 msg is a whole object GCC
doesn't warn with the patch.  If msg were a reference passed to func() then GCC
would treat the array as a flexible array member and the optimization would not
take place.  But in that case, memcpy treats a pointer to such an array as
pointing to an object of potentially larger size and so no warning is issued
either.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]