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

Peter Hutterer peter.hutterer at who-t.net
Tue Jul 27 16:26:21 PDT 2010


On Tue, Jul 27, 2010 at 03:09:56PM +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
> possible if source doesn't have NULL.

same argument as for the other patch.

> memcpy will initialize whole array/structure so memset is redurant and
              ^ better use "copy", not "initialize" to avoid confusion.

> can be removed.

Cheers,
  Peter
 
> Signed-off-by: Pauli Nieminen <ext-pauli.nieminen at nokia.com>
> ---
>  xkb/XKBGAlloc.c |    8 +++-----
>  1 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/xkb/XKBGAlloc.c b/xkb/XKBGAlloc.c
> index 9a768ca..2f7dc84 100644
> --- a/xkb/XKBGAlloc.c
> +++ b/xkb/XKBGAlloc.c
> @@ -693,8 +693,7 @@ register XkbKeyAliasPtr alias;
>  	return NULL;
>      for (i=0,alias=geom->key_aliases;i<geom->num_key_aliases;i++,alias++) {
>  	if (strncmp(alias->alias,aliasStr,XkbKeyNameLength)==0) {
> -	    memset(alias->real, 0, XkbKeyNameLength);
> -	    strncpy(alias->real,realStr,XkbKeyNameLength);
> +	    memcpy(alias->real,realStr,XkbKeyNameLength);
>  	    return alias;
>  	}
>      }
> @@ -703,9 +702,8 @@ register XkbKeyAliasPtr alias;
>  	return NULL;
>      }
>      alias= &geom->key_aliases[geom->num_key_aliases];
> -    memset(alias, 0, sizeof(XkbKeyAliasRec));
> -    strncpy(alias->alias,aliasStr,XkbKeyNameLength);
> -    strncpy(alias->real,realStr,XkbKeyNameLength);
> +    memcpy(alias->alias,aliasStr,XkbKeyNameLength);
> +    memcpy(alias->real,realStr,XkbKeyNameLength);
>      geom->num_key_aliases++;
>      return alias;
>  }
> -- 
> 1.6.3.3


More information about the xorg-devel mailing list