Get the latest tech news

I'm not a fan of strlcpy(3)


strlcpy(3) is an OpenBSD function which is often hailed as a safer replacement for strcpy(3) and/or strncpy(3). One of the obvious issues with strlcpy is that it's not safe if src isn't null-terminated.

The reason why I'm not a fan of it is because I've recently revisited this old thread where Ulrich Drepper rejects the proposal to add strlcpy to glibc. For example, if we're trying to display the result on some statusbar which can only hold, let's say 64 bytes, then not only is the src string getting truncated is not an issue, it's actually wanted since it makes no sense to copy more than that. And in case you're worried about this being two-liners as opposed to a one-liner strlcpy call (which is a valid criticism, as that can open up room for making mistake), then you can (and should) simply turn this two liner into a wrapper function.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Fan

Fan

Photo of strlcpy(3

strlcpy(3

Related news:

News photo

Fan-made Elden Ring anime adaptation receives teaser trailer

News photo

Dragon Age: The Veilguard first-look reveals companions and fan-favourite returning character

News photo

PSA: If you're a fan of ATmega, try AVR Dx