[PATCH 14/15] xkb: Use memcpy for copy
Peter Hutterer
peter.hutterer at who-t.net
Tue Jul 27 16:25:10 PDT 2010
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.
strncpy and memcpy would achieve the same thing here but given that we're
dealing with a string here I find strncpy more obvious to read.
Cheers,
Peter
> Signed-off-by: Pauli Nieminen <ext-pauli.nieminen at nokia.com>
> ---
> xkb/XKBGAlloc.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/xkb/XKBGAlloc.c b/xkb/XKBGAlloc.c
> index 7143e7a..9a768ca 100644
> --- a/xkb/XKBGAlloc.c
> +++ b/xkb/XKBGAlloc.c
> @@ -922,8 +922,8 @@ Bool found;
> if ((row->num_keys>=row->sz_keys)&&(_XkbAllocOverlayKeys(row,1)!=Success))
> return NULL;
> key= &row->keys[row->num_keys];
> - strncpy(key->under.name,under,XkbKeyNameLength);
> - strncpy(key->over.name,over,XkbKeyNameLength);
> + memcpy(key->under.name,under,XkbKeyNameLength);
> + memcpy(key->over.name,over,XkbKeyNameLength);
> row->num_keys++;
> return key;
> }
> --
> 1.6.3.3
More information about the xorg-devel
mailing list