On Fri, May 29, 2020 at 3:20 PM Harald Anlauf <anl...@gmx.de> wrote:
>
> Hi H.J.,
>
> > Gesendet: Freitag, 29. Mai 2020 um 23:57 Uhr
> > Von: "H.J. Lu" <hjl.to...@gmail.com>
>
> > This breaks bootstrap:
> >
> > https://gcc.gnu.org/pipermail/gcc-regression/2020-May/072642.html
> >
> > ../../src-master/gcc/fortran/class.c:487:13: error: ‘char*
> > strncpy(char*, const char*, size_t)’ specified bound 67 equals
> > destination size [-Werror=stringop-truncation]
> >   487 |     strncpy (dt_name, gfc_dt_upper_string (derived->name),
> > sizeof (dt_name));
>
> what is the right way to deal with that?
>
> I haven't seen any use of strlcpy in the gcc sources.  This would do
> the right thing and would fit here.
>
> So should one use the clumsy way:
>
>            strncpy(buf, str, buflen - 1);
>            if (buflen > 0)
>                buf[buflen - 1]= '\0';
>
> Or is there something more convenient that keeps gcc happy?

dt_name[sizeof (dt_name) - 1] = '\0';
strncpy (dt_name, gfc_dt_upper_string (derived->name), sizeof (dt_name) - 1);


-- 
H.J.

Reply via email to