Ushering out strlcpy()
Ushering out strlcpy()
Posted Aug 26, 2022 6:53 UTC (Fri) by wtarreau (subscriber, #51152)In reply to: Ushering out strlcpy() by kees
Parent article: Ushering out strlcpy()
Agreed, I too would like to see strncpy() disappear, as it tends to lie to the reader. I've seen it be entirely responsible for major slowdowns a few times in different projects by the way, where users did not realize that it was padding the whole target buffer. And the number of times you see it called in series to concatenate path elements, you can't avoid thinking "OK I have an overflow after the first one". The only valid case I know for it in userland is to write a UNIX socket path because sun_path is of fixed length and not necessarily 0-terminated :-/ But that clearly demonstrates that str_anything_pad() would be a more suitable name for this thing (though memset(end, 0, size-len)
based on strscpy()'s return would work too).
based on strscpy()'s return would work too).
