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

Pauli Nieminen ext-pauli.nieminen at nokia.com
Tue Jul 27 05:09:56 PDT 2010


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.

memcpy will initialize whole array/structure so memset is redurant and
can be removed.

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