[PATCH 14/15] xkb: Use memcpy for copy
Pauli Nieminen
ext-pauli.nieminen at nokia.com
Wed Jul 28 04:11:05 PDT 2010
On 28/07/10 11:48 +0200, ext Mark Kettenis wrote:
> > Date: Wed, 28 Jul 2010 09:25:10 +1000
> > From: Peter Hutterer <peter.hutterer at who-t.net>
> >
> > On Tue, Jul 27, 2010 at 03:09:55PM +0300, Pauli Nieminen wrote:
> > > Source and destination have well defined size so use memcpy instead of
> > > strncpy. strncpy tryes to add NULL to end of destination but it is not
> > ^ "tries"
> > > possible if source doesn't have NULL.
> >
> > my strncpy man page claims that if there is "no null byte among the first n
> > bytes of src, the string placed in dest will not be null terminated." That's
> > counter to what the message above says.
static analyzer complains about possible missing NULL termination for string,
Also code is already mainly using memcpy for same copy in other places. That
why I tough change to memcpy would make sense. I should have added that to
commit message.
>
> That's correct. It's why strlcpy(3) was invented in the non-Linux
> world; strlcpy(3) guarantees that the copied string is
> null-terminated.
>
> So I agree with Peter that this change doesn't make a lot of sense.
> Potentially strncpy(3) will be faster than memcpy(3) since it will
> stop copying after a null character.
memcpy will be faster unless you can skip a lot of memory areal. Checking for
each byte for NULL is a lot more expensive than just doing copy unconditionaly.
More information about the xorg-devel
mailing list