fix warnings from gcc-10
cover fix warnings from gcc-10
Just switched over to Gcc-10 which complains about a number of small issues in iproute2.
Stephen Hemminger (5):
devlink: fix unitialized warning
bridge: fix string length warning
tc: fix compiler warnings in ip6 pedit
misc: fix compiler warning in ifstat and nstat
f_u32: fix compiler gcc-10 compiler warning
devlink/devlink.c | 2 +- ip/iplink_bridge.c | 2 +- misc/ifstat.c | 2 +- misc/nstat.c | 3 +-- tc/f_u32.c | 2 +- tc/p_ip6.c | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-)
Signature · 1 line
2.29.2
PATCH 1/5 devlink: fix unitialized warning
GCC-10 complains about uninitialized variable.
devlink.c: In function ‘cmd_dev’:
devlink.c:2803:12: warning: ‘val_u32’ may be used uninitialized in this function [-Wmaybe-uninitialized]
2803 | val_u16 = val_u32;
| ~~~~~~~~^~~~~~~~~
devlink.c:2747:11: note: ‘val_u32’ was declared here
2747 | uint32_t val_u32;
| ^~~~~~~This is a false positive because it can't figure out the control flow when the parse returns error. Simplest fix is to initialize variable.
--- devlink/devlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
devlink/devlink.c +1 -1
@@ -2744,7 +2744,7 @@ static int cmd_dev_param_set(struct dl *dl)struct param_ctx ctx = {};struct nlmsghdr *nlh;bool conv_exists; -uint32_t val_u32; +uint32_t val_u32 =0 ;uint16_t val_u16;uint8_t val_u8;bool val_bool;
Signature · 1 line
2.29.2
PATCH 2/5 bridge: fix string length warning
In reply to Stephen HemmingerGcc-10 complains about possible string length overflow. This can't happen Ethernet address format is always limited to 18 characters or less. Just resize the temp buffer.
--- ip/iplink_bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ip/iplink_bridge.c +1 -1
@@ -74,7 +74,7 @@ static void explain(void)void br_dump_bridge_id (const struct ifla_bridge_id *id,char *buf,size_t len) { -char eaddr[32 ]; +char eaddr[18 ];ether_ntoa_r ((const struct ether_addr *)id->addr, eaddr);snprintf (buf, len,"%.2x%.2x.%s" , id->prio[0 ], id->prio[1 ], eaddr);
Signature · 1 line
2.29.2
PATCH 3/5 tc: fix compiler warnings in ip6 pedit
In reply to Stephen HemmingerGcc-10 complains about referencing a zero size array. This occurs because the array of keys is actually in the following structure which is part of the overall selector.
The original code was safe, but better to just use the key array directly.
--- tc/p_ip6.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tc/p_ip6.c +1 -1
@@ -82,7 +82,7 @@ parse_ip6(int *argc_p, char ***argv_p,/* Shift the field by 4 bits on success. */ if (!res) {int nkeys = sel->sel.nkeys; -struct tc_pedit_key *key = &sel->sel.keys[nkeys -1 ]; +struct tc_pedit_key *key = &sel->keys[nkeys -1 ]; key->mask =htonl (ntohl (key->mask) <<4 |0xf ); key->val =htonl (ntohl (key->val) <<4 );
Signature · 1 line
2.29.2
PATCH 4/5 misc: fix compiler warning in ifstat and nstat
In reply to Stephen HemmingerThe code here was doing strncpy() in a way that causes gcc 10 warning about possible string overflow. Just use strlcpy() which will null terminate and bound the string as expected.
This has existed since start of git era so no Fixes tag.
--- misc/ifstat.c | 2 +- misc/nstat.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)
misc/ifstat.c +1 -1
@@ -251,7 +251,7 @@ static void load_raw_table(FILE *fp) buf[strlen (buf)-1 ] =0 ;if (info_source[0 ] &&strcmp (info_source, buf+1 )) source_mismatch =1 ; -strncpy (info_source, buf+1 ,sizeof (info_source)-1 ); +strlcpy (info_source, buf+1 ,sizeof (info_source));continue ; }if ((n =malloc (sizeof (*n))) ==NULL )
misc/nstat.c +1 -2
@@ -136,8 +136,7 @@ static void load_good_table(FILE *fp) buf[strlen (buf)-1 ] =0 ;if (info_source[0 ] &&strcmp (info_source, buf+1 )) source_mismatch =1 ; - info_source[0 ] =0 ; -strncat (info_source, buf+1 ,sizeof (info_source)-1 ); +strlcpy (info_source, buf +1 ,sizeof (info_source));continue ; }/* idbuf is as big as buf, so this is safe */
Signature · 1 line
2.29.2
PATCH 5/5 f_u32: fix compiler gcc-10 compiler warning
In reply to Stephen HemmingerWith gcc-10 it complains about array subscript error.
f_u32.c: In function ‘u32_parse_opt’:
f_u32.c:1113:24: warning: array subscript 0 is outside the bounds of an interior zero-length array ‘struct tc_u32_key[0]’ [-Wzero-length-bounds]
1113 | hash = sel2.sel.keys[0].val & sel2.sel.keys[0].mask;
| ~~~~~~~~~~~~~^~~
In file included from tc_util.h:11,
from f_u32.c:26:
../include/uapi/linux/pkt_cls.h:253:20: note: while referencing ‘keys’
253 | struct tc_u32_key keys[0];
|This is because the keys are actually allocated in the second element of the parent structure.
Simplest way to address the warning is to assign directly to the keys in the containing structure.
This has always been in iproute2 (pre-git) so no Fixes.
--- tc/f_u32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tc/f_u32.c +1 -1
@@ -1110,7 +1110,7 @@ static int u32_parse_opt(struct filter_util *qu, char *handle, }NEXT_ARG (); } - hash = sel2.sel.keys[0 ].val & sel2.sel.keys[0 ].mask; + hash = sel2.keys[0 ].val & sel2.keys[0 ].mask; hash ^= hash >>16 ; hash ^= hash >>8 ; htid = ((hash % divisor) <<12 ) | (htid &0xFFF00000 );
Signature · 1 line
2.29.2
Quoted 10 lines · On Sun, 29 Nov 2020 09:54:32 -0800 Stephen Hemminger…
Just switched over to Gcc-10 which complains about a number of small issues in iproute2.
Stephen Hemminger (5):
devlink: fix unitialized warning
bridge: fix string length warning
tc: fix compiler warnings in ip6 pedit
misc: fix compiler warning in ifstat and nstat
f_u32: fix compiler gcc-10 compiler warning
Quoted 8 lines
devlink/devlink.c | 2 +- ip/iplink_bridge.c | 2 +- misc/ifstat.c | 2 +- misc/nstat.c | 3 +-- tc/f_u32.c | 2 +- tc/p_ip6.c | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-)
Ignore this meant to go to netdev, and send-email became automatic to [email protected]