At Mon, 6 Jan 2025 01:29:26 +0000, David Holland <dholland-tech%netbsd.org@localhost> wrote: Subject: Re: Usage of strncpy in the kernel > > On Sun, Jan 05, 2025 at 01:06:41PM -0800, Greg A. Woods wrote: > > > I used the "l" because like strlcpy they (should) check all the > > > lengths and won't overrun. > > > > I think you may be confusing strlcpy() and strlcat(). > > Huh? The difference between strcpy and strlcpy is the "l" and the > length checking. As I said, there is no "length" checking in strlcpy() _unless_ perhaps one confuses truncation checking with length checking, but even then the truncation checking is left to the caller and it is only tangentially related to the 'size' parameter. The 'size' parameter effectively only does the same thing in strlcpy() as it does in strncpy(), except of course it copies one byte less than strncpy() does, and then it substitutes a NUL instead of copying the last byte. Interestingly, though it is not spelled out this way explicitly in the manual page, strlcpy() is effectively strlen(src) when 'size == 0'. -- Greg A. Woods <gwoods%acm.org@localhost> Kelowna, BC +1 250 762-7675 RoboHack <woods%robohack.ca@localhost> Planix, Inc. <woods%planix.com@localhost> Avoncote Farms <woods%avoncote.ca@localhost>
Attachment:
pgpH361e6t7ks.pgp
Description: OpenPGP Digital Signature