[PATCH v2 6/7] xkb: Use memcpy for copy

Pauli Nieminen ext-pauli.nieminen at nokia.com
Wed Jul 28 12:47:06 PDT 2010


Source is not NULL terminated string so using memcpy instead of strncpy
makes more sense.

All other places doing same copy are using memcpy.

memset is redurant because memcpy will write usefull values anyway.

fixes:
Calling strncpy with a maximum size argument of (4) on destination
buffer "alias->real" of size (4) can possibly leave the destination
buffer lacking null-termination

Signed-off-by: Pauli Nieminen <ext-pauli.nieminen at nokia.com>
---

improved commit message

 xkb/XKBGAlloc.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/xkb/XKBGAlloc.c b/xkb/XKBGAlloc.c
index 170d297..a15cd2e 100644
--- a/xkb/XKBGAlloc.c
+++ b/xkb/XKBGAlloc.c
@@ -691,8 +691,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;
 	}
     }
@@ -701,9 +700,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