> On Sep 7, 2020, at 5:55 AM, Florian Weimer <fwei...@redhat.com> wrote: > > * Kim Barrett: > >> And strlen is not even necessarily the best solution, as it likely >> introduces an additional otherwise unnecessary string traversal. For >> example, getFlags could be changed to reject an overly long ifname, >> without using strlen, thusly: >> >> strncpy(if2.ifr_name, ifname, sizeof(if2.ifr_name)); >> if (if2.ifr_name[sizeof(if2.ifr_name) - 1] != '\0') { >> return -1; >> } >> >> Unfortunately, gcc10 -Wstringop-truncation whines about this entirely >> reasonable code. > > Thanks, I filed this as: > <https://urldefense.com/v3/__https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96951__;!!GqivPVa7Brio!LVecE16VyMwNW6-aTnJEfSMgHgOZDIrswH8f0svlQJWAQfrOqqXaq-i7q508_5Eb$ > >
Thanks. Though it looks like the response is just “don’t use strncpy”.