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)
Sep 29 2024, 11:14 AM
Unknown Object (File)
Sep 29 2024, 9:21 AM
Unknown Object (File)
Sep 27 2024, 2:19 AM
Unknown Object (File)
Sep 27 2024, 2:19 AM
Unknown Object (File)
Sep 27 2024, 2:19 AM
Unknown Object (File)
Sep 27 2024, 2:19 AM
Unknown Object (File)
Sep 25 2024, 7:02 PM
Unknown Object (File)
Sep 25 2024, 7:01 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.