A turning point for GNU libc
Posted Mar 31, 2012 21:35 UTC (Sat) by
lacos (subscriber, #70616)
In reply to:
A turning point for GNU libc by wahern
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.
(
Log in to post comments)