From: Linus Torvalds <email@example.com>
Subject: Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
Date: Sun, 25 May 2003 03:54:06 GMT
On Sat, 24 May 2003, Ben Collins wrote:
> Given that the problem with KOBJ_NAME_LEN == 20 affecting one snd driver
> has so far only been explained as a compiler bug, can I suggest this
> patch be applied? Even aside from the KOBJ_NAME_LEN == 20, the snprintf
> changes will keep things from breaking in other ways that are current
I hate using snprintf() for this kind of mindless string copy opertation.
Yeah, "strncpy()" is a frigging disaster when it comes to '\0', in many
ways. We should probably disallow using strncpy(), and aim for a _sane_
implementation that does what we actually want (none of that zero-padding
crap, and _always_ put a NUL at the end). I bet that is what most current
strncpy() users actually would want.
But switching it over to "snprintf()" is overkill.
How about just adding a sane
int copy_string(char *dest, const char *src, int len)
size = strlen(src);
if (size >= len)
size = len-1;
memcpy(dest, src, size);
dest[size] = '\0';
which is what pretty much everybody really _wants_ to have anyway? We
should deprecate "strncpy()" within the kernel entirely.