A turning point for GNU libc
Posted Mar 31, 2012 21:35 UTC (Sat) by lacos
In reply to: A turning point for GNU libc
Parent article: A turning point for GNU libc
truncation isn't silent: if (sizeof buf <= strlcpy(buf, str, sizeof buf)) oops("truncated!");
I don't like this. strlcpy() continues to find the end / length of the source string even if the target buffer has ended way earlier. And it does it every single time.
Instead of this, know the length of your source string (which takes a single strlen() in the beginning), and allocate the target buffer accordingly. Or, if the target is a given, and too small, bail out before copying any characters.
to post comments)