[PATCH 14/15] xkb: Use memcpy for copy

Daniel Stone daniel at fooishbar.org
Wed Jul 28 04:26:19 PDT 2010


On Wed, Jul 28, 2010 at 02:11:05PM +0300, Pauli Nieminen wrote:
> > > 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.

It doesn't need to be NULL-terminated; all the key names are always 4
bytes long (cf. XkbKeyNameLength), so to use it as a string, you copy it
out to a five-byte array and then NULL-terminate it.

Cheers,
Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.x.org/archives/xorg-devel/attachments/20100728/aed04f56/attachment.pgp>


More information about the xorg-devel mailing list