diff options
author | Adam Jackson <ajax@redhat.com> | 2018-04-05 12:59:11 -0400 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2018-04-05 14:18:47 -0400 |
commit | 83913de25d35709b3ab7b0ab124b73924145d2dd (patch) | |
tree | 94c280df8596a505f03b80154db627bac54c5eb6 | |
parent | d13cd3862e9ccd35c91a06680d02f2fc8fd03420 (diff) |
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 <ajax@redhat.com>
Acked-by: Keith Packard <keithp@keithp.com>
-rw-r--r-- | xkb/XKBGAlloc.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/xkb/XKBGAlloc.c b/xkb/XKBGAlloc.c index e9f55fa43..8958b0c52 100644 --- a/xkb/XKBGAlloc.c +++ b/xkb/XKBGAlloc.c @@ -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))); geom->num_key_aliases++; return alias; } @@ -814,8 +815,8 @@ XkbAddGeomOverlayKey(XkbOverlayPtr overlay, (_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, min(XkbKeyNameLength, strlen(under))); + memcpy(key->over.name, over, min(XkbKeyNameLength, strlen(over))); row->num_keys++; return key; } |