News for hackers. Stuff that matters.
Re:Stop using strncpy already by charliesome on Thursday April 04, 2013 @03:34AM (#5491469)
Here's a better idea: Stop using the str* functions completely. Start using buffers with explicit length fields attached, and start using the mem* functions.
Re:Stop using strncpy already by simias on Thursday April 04, 2013 @04:51AM (#5491639)
Each has its uses. The standard C and C++ library use C-strings for many things, so if you want to use, say, fopen you'd have to have a conversion routine set up (at additional memory and cpu cost). Just yesterday the ex-protobuf guy explained that in his new format (whose name I forgot) he uses null terminated strings exactly for that, even though he also stores the length of the string already.

But then, it's just C strings vs. Pascal strings all over again. It's your job as an engineer to use the right tool at the right time.

On the other end, it sucks that strlcpy is not as portable as the n counterparts. Last time I checked, the gnu libc still didn't have it for stupid bikeshed reasons.

Re:Stop using strncpy already by Nick_C on Thursday April 04, 2013 @09:50PM (#5496413)
> the gnu libc still didn't have it for stupid bikeshed reasons

Yep, still doesn't. Not so much for bikeshed reasons, but more for the Gnu people's stupid NIH reasons. OpenBSD offered it to them, reply was along the lines of "we don't see the need for it".

Re:Stop using strncpy already by evadne on Thursday April 04, 2013 @05:56AM (#5491769)