From 813acdd2df24a8e3f44152d90a26f1beef11b38c Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Fri, 21 Jun 2019 11:01:59 +0200 Subject: xkb: Silence some compiler warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 83913de25d35709b3ab7b0ab124b73924145d2dd Author: Adam Jackson Date: Thu Apr 5 12:59:11 2018 -0400 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 Acked-by: Keith Packard --- nx-X11/programs/Xserver/xkb/XKBGAlloc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/programs/Xserver/xkb/XKBGAlloc.c b/nx-X11/programs/Xserver/xkb/XKBGAlloc.c index ac757232e..bfbd0c325 100644 --- a/nx-X11/programs/Xserver/xkb/XKBGAlloc.c +++ b/nx-X11/programs/Xserver/xkb/XKBGAlloc.c @@ -702,7 +702,8 @@ register XkbKeyAliasPtr alias; for (i=0,alias=geom->key_aliases;inum_key_aliases;i++,alias++) { if (strncmp(alias->alias,aliasStr,XkbKeyNameLength)==0) { bzero(alias->real,XkbKeyNameLength); - strncpy(alias->real,realStr,XkbKeyNameLength); + memcpy(alias->real, realStr, + min(XkbKeyNameLength, strlen(realStr))); return alias; } } @@ -712,8 +713,8 @@ register XkbKeyAliasPtr alias; } alias= &geom->key_aliases[geom->num_key_aliases]; bzero(alias,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; } @@ -930,8 +931,8 @@ Bool found; if ((row->num_keys>=row->sz_keys)&&(_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; } -- cgit v1.2.3