diff options
author | Antonio Borneo <borneo.antonio@gmail.com> | 2020-04-27 23:19:14 +0200 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2020-05-09 14:36:56 +0100 |
commit | 4738a55da416176542efa1b554020de275a5b4e5 (patch) | |
tree | 2474addeb568b6e9d6be289e48c643827f624b31 | |
parent | 8807a5937e5fe5d09828c3e535beafb48e171621 (diff) | |
download | riscv-openocd-4738a55da416176542efa1b554020de275a5b4e5.zip riscv-openocd-4738a55da416176542efa1b554020de275a5b4e5.tar.gz riscv-openocd-4738a55da416176542efa1b554020de275a5b4e5.tar.bz2 |
helper/ioutil: silence gcc-8 on strncpy
Starting from version 8, gcc issues a warning if strncpy could be
able to truncate a string (so without adding the zero-termination
char in destination) by copying exactly "size" char from a source
string not shorter than "size".
Such truncation from strncpy could actually be the desired code
behaviour, but the way to silent gcc only locally (without global
disabling with -Wno-stringop-truncation) through pragma has other
side effects on portability.
In current code, the source string is always "eth0", because has
been checked right above. So this is a false positive from gcc,
being always strlen("eth0") < 16, the sizeof(ifreq.ifr_name).
Silent gcc by decrementing the "size" and remove:
error: ‘strncpy’ specified bound 16 equals destination
size [-Werror=stringop-truncation]
This file is only optionally compiled together with ZY1000 driver
with --enable-zy1000 --enable-ioutil. This combination is not
checked in jenkins, so the error passed unnoticed.
Plus, the configure flags above are both deprecated!
Change-Id: I229e66227cfd3513139feeaffa47a6e1ec00767b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5631
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
-rw-r--r-- | src/helper/ioutil.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c index d4f39e2..c103ce1 100644 --- a/src/helper/ioutil.c +++ b/src/helper/ioutil.c @@ -403,7 +403,7 @@ static int ioutil_Jim_Command_mac(Jim_Interp *interp, int argc, { if (strcmp("eth0", ifr->ifr_name) != 0) continue; - strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name)); + strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name) - 1); if (ioctl(SockFD, SIOCGIFHWADDR, &ifreq) < 0) { close(SockFD); return JIM_ERR; |