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

Kristian Høgsberg krh at bitplanet.net
Wed Jul 28 06:00:51 PDT 2010


On Wed, Jul 28, 2010 at 7:26 AM, Daniel Stone <daniel at fooishbar.org> wrote:
> 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.

Or you can use %.4s if you're just printf-ing it.

Kristian


More information about the xorg-devel mailing list