Page MenuHomeFreeBSD

libfetch: Use memcpy in place of an odd strncpy.
ClosedPublic

Authored by jhb on Sep 29 2022, 10:36 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, May 6, 8:40 AM
Unknown Object (File)
Wed, May 1, 12:44 PM
Unknown Object (File)
Thu, Apr 25, 1:31 PM
Unknown Object (File)
Thu, Apr 25, 1:31 PM
Unknown Object (File)
Tue, Apr 23, 9:37 AM
Unknown Object (File)
Mon, Apr 22, 9:30 AM
Unknown Object (File)
Mon, Apr 22, 9:16 AM
Unknown Object (File)
Wed, Apr 17, 4:28 PM
Subscribers

Details

Summary

The length passed to strncpy is the length of the source string, not
the destination buffer. This triggers a non-fatal warning in GCC 12.
Hoewver, the code is also odd. It is really just a memcpy of the
string without its nul terminator. For that use case, memcpy is
clearer.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Sep 29 2022, 10:36 PM

Note to self: fix spelling of "However" in log message.

This revision is now accepted and ready to land.Sep 30 2022, 2:46 AM

Looks like a job for strlcpy()...

This looks good to me. I disagree strlcpy() is right here. This is a fixed length copy w/o a NUL termination.

This revision was automatically updated to reflect the committed changes.