[Bug libgomp/83106] [8 regression] libgomp/target.c:2671:2: error: ‘strncat’ specified bound 5 equals source length [-Werror=stringop-overflow=]

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Nov 22 13:11:00 GMT 2017


Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2017-11-22
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 42678
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42678&action=edit

I think the warning is just bogus for strncat.  Unlike strncpy, which is weird,
sometimes doesn't terminate, sometimes unnecessarily fills with zeros and the
third argument represents the size of the destination (so indeed specifying the
size based on strlen of the source might be a bug), strncat does something
different, the third argument is the max number of chars to take from the src
string; and strncat always terminates.  So, passing strlen (src) as third
argument is nothing problematic, it is just another way of specifying strcat,
using something strlen based is sane too (both smaller or larger).

That said, the code in target.c is ugly and relies on tree-ssa-strlen.c pass to
fix the mess up, so I'll test and commit the attached patch.

More information about the Gcc-bugs mailing list