Commit 83913de2 authored by Adam Jackson's avatar Adam Jackson 🥃

xkb: Silence some compiler warnings

Of the form:

../xkb/XKBGAlloc.c: In function ‘SrvXkbAddGeomKeyAlias’:
../xkb/XKBGAlloc.c:591:13: warning: ‘strncpy’ specified bound 4 equals destination size [-Wstringop-truncation]
             strncpy(alias->real, realStr, XkbKeyNameLength);

This is intentional; the code that reads from these fields never reads
more than 4 bytes anyway. Rephrase things in terms of memcpy so that's
clear. Obviously this is awful but in XKB awful is par.
Signed-off-by: Adam Jackson's avatarAdam Jackson <>
Acked-by: Keith Packard's avatarKeith Packard <>
parent d13cd386
......@@ -588,7 +588,8 @@ XkbAddGeomKeyAlias(XkbGeometryPtr geom, char *aliasStr, char *realStr)
i++, alias++) {
if (strncmp(alias->alias, aliasStr, XkbKeyNameLength) == 0) {
memset(alias->real, 0, XkbKeyNameLength);
strncpy(alias->real, realStr, XkbKeyNameLength);
memcpy(alias->real, realStr,
min(XkbKeyNameLength, strlen(realStr)));
return alias;
......@@ -598,8 +599,8 @@ XkbAddGeomKeyAlias(XkbGeometryPtr geom, char *aliasStr, char *realStr)
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, min(XkbKeyNameLength, strlen(aliasStr)));
memcpy(alias->real, realStr, min(XkbKeyNameLength, strlen(realStr)));
return alias;
......@@ -814,8 +815,8 @@ XkbAddGeomOverlayKey(XkbOverlayPtr overlay,
(_XkbAllocOverlayKeys(row, 1) != Success))
return NULL;
key = &row->keys[row->num_keys];
strncpy(key->, under, XkbKeyNameLength);
strncpy(key->, over, XkbKeyNameLength);
memcpy(key->, under, min(XkbKeyNameLength, strlen(under)));
memcpy(key->, over, min(XkbKeyNameLength, strlen(over)));
return key;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment