Re: [HACKERS] Coding note: truncating with strlcpy() is not such a hot idea

2015-12-21 Thread Noah Misch
On Mon, Dec 21, 2015 at 03:47:56PM -0500, Tom Lane wrote: > 1. Using strlcpy to copy from sources that are not known null-terminated > is outright unsafe: someday, you'll fall off the end of memory and > SIGSEGV. > > 2. Even with a known null-terminated string, using strlcpy to chop small > pieces

[HACKERS] Coding note: truncating with strlcpy() is not such a hot idea

2015-12-21 Thread Tom Lane
There's been some effort to replace uses of strncpy() and our homegrown StrNCpy() macro with strlcpy(). I had my nose rubbed today in the fact that that isn't always a good transformation. The reason why not is that strlcpy() is defined to return strlen(src), which means that even after it's tran