Re: [hackers] [dwm] [PATCH] Replace str[n]cpy with strlcpy

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Fri, 3 Jun 2016 19:00:05 +0200

On Thu, Jun 02, 2016 at 09:57:01PM +0200, FRIGN wrote:
> Hello fellow hackers,
>
> I'll drop this little patch here so we finally make the switch to the
> safe OpenBSD-functions for string copying.

A good compromise might be using snprintf(buf, sizeof(buf), "%s", text) this is
standard and functionally exactly the same as using strlcpy.

I agree the strncpy functions need to go, they don't make sense in this
context.

Some people forget strncpy has the following properties aswell, from the
OpenBSD man page:

"If src is less than len characters long, it fills the remaining buffer
with '\0' characters".

and

"strncpy() only NUL terminates the destination string when the length of
the source string is less than the length parameter."

-- 
Kind regards,
Hiltjo
Received on Fri Jun 03 2016 - 19:00:05 CEST

This archive was generated by hypermail 2.3.0 : Fri Jun 03 2016 - 19:12:11 CEST