Skip to contentSkip to conversation

compiler warning fixes

PATCH Applied Stephen Hemminger 2 participants 5 messages Aug 23 – Aug 25

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover compiler warning fixes

Three small patches that fix warnings when iproute2 is built with latest GCC-17 and/or Clang-21.

Stephen Hemminger (3):
json_print: fix Gcc-17 warnings
lib: fix warning from ll_addr_a2n
tc/f_u32: fix const strchr() warning

 include/json_print.h |  4 ++--
 lib/ll_addr.c        | 52 +++++++++++++++++++++++---------------------
 tc/f_u32.c           |  6 +++--
 3 files changed, 33 insertions(+), 29 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/3 json_print: fix Gcc-17 warnings

Lastest version of Gcc and Clang warn about value of 2 in
logical operator. Example:
warning: use of logical ‘&&’ with constant operand ‘2’ [-Wconstant-logical-operand]

---
 include/json_print.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/json_print.h +2 -2
index 6a458189..79d8d4ff 100644
@@ -15,8 +15,8 @@
 #include "json_writer.h"
 #include "color.h"
 
-#define _IS_JSON_CONTEXT(type) (is_json_context() && (type & PRINT_JSON || type & PRINT_ANY))
-#define _IS_FP_CONTEXT(type)   (!is_json_context() && (type & PRINT_FP || type & PRINT_ANY))
+#define _IS_JSON_CONTEXT(type) (is_json_context() && !!((type) & (PRINT_JSON | PRINT_ANY)))
+#define _IS_FP_CONTEXT(type)   (!is_json_context() && !!((type) & (PRINT_FP | PRINT_ANY)))
 
 json_writer_t *get_json_writer(void);
 
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/3 lib: fix warning from ll_addr_a2n

In reply to Stephen Hemminger

Recent versions of strchr() propogate const char *. This triggers warnings about lost of const. Resolve this by reworking the loop parsing hex values. This also adds checking for garbage after the hex value.

Also:
- arg is no longer modified
- Trailing garbage ("00:11:zz", "00:11:") are now rejected
- An address longer than len bytes now fails

---
 lib/ll_addr.c | 52 ++++++++++++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 25 deletions(-)
lib/ll_addr.c +27 -25
index 7a9eb3a4..851a5be0 100644
@@ -7,6 +7,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <ctype.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
@@ -45,8 +46,12 @@ const char *ll_addr_n2a(const unsigned char *addr, int alen, int type,
 /*NB: lladdr is char * (rather than u8 *) because sa_data is char * (1003.1g) */
 int ll_addr_a2n(char *lladdr, int len, const char *arg)
 {
+	const char *cp;
+	int i;
+
 	if (strchr(arg, '.')) {
 		inet_prefix pfx;
+
 		if (get_addr_1(&pfx, arg, AF_INET)) {
 			fprintf(stderr, "\"%s\" is invalid lladdr.\n", arg);
 			return -1;
@@ -55,31 +60,28 @@ int ll_addr_a2n(char *lladdr, int len, const char *arg)
 			return -1;
 		memcpy(lladdr, pfx.data, 4);
 		return 4;
-	} else {
-		int i;
+	}
 
-		for (i = 0; i < len; i++) {
-			int temp;
-			char *cp = strchr(arg, ':');
-			if (cp) {
-				*cp = 0;
-				cp++;
-			}
-			if (sscanf(arg, "%x", &temp) != 1) {
-				fprintf(stderr, "\"%s\" is invalid lladdr.\n",
-					arg);
-				return -1;
-			}
-			if (temp < 0 || temp > 255) {
-				fprintf(stderr, "\"%s\" is invalid lladdr.\n",
-					arg);
-				return -1;
-			}
-			lladdr[i] = temp;
-			if (!cp)
-				break;
-			arg = cp;
-		}
-		return i + 1;
+	for (i = 0, cp = arg; i < len; i++) {
+		unsigned long val;
+		char *endp;
+
+		if (!isxdigit(*cp))
+			goto invalid;
+
+		val = strtoul(cp, &endp, 16);
+		if (val > 255)
+			goto invalid;
+
+		lladdr[i] = val;
+
+		if (*endp == '\0')
+			return i + 1;
+		if (*endp != ':')
+			goto invalid;
+		cp = endp + 1;
 	}
+invalid:
+	fprintf(stderr, "\"%s\" is invalid lladdr.\n", arg);
+	return -1;
 }
Signature · 1 line
2.53.0
#3 lore raw

PATCH 3/3 tc/f_u32: fix const strchr() warning

In reply to Stephen Hemminger

Newer GCC propogates const char across strchr() which requires spliting temp variable.

---
 tc/f_u32.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tc/f_u32.c +4 -2
index 088d744e..ae285146 100644
@@ -41,13 +41,15 @@ static void explain(void)
 static int get_u32_handle(__u32 *handle, const char *str)
 {
 	__u32 htid = 0, hash = 0, nodeid = 0;
-	char *tmp = strchr(str, ':');
+	const char *colon = strchr(str, ':');
+	char *tmp;
 
-	if (tmp == NULL) {
+	if (colon == NULL) {
 		if (memcmp("0x", str, 2) == 0)
 			return get_u32(handle, str, 16);
 		return -1;
 	}
+
 	htid = strtoul(str, &tmp, 16);
 	if (tmp == str && *str != ':' && *str != 0)
 		return -1;
Signature · 1 line
2.53.0
#4 lore raw
In reply to Stephen Hemminger
This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Hello:

This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Quoted 9 lines · On Sun, 23 Aug 2026 16:51:30 -0700 you wrote:

Three small patches that fix warnings when iproute2 is built with latest GCC-17 and/or Clang-21.

Stephen Hemminger (3):
json_print: fix Gcc-17 warnings
lib: fix warning from ll_addr_a2n
tc/f_u32: fix const strchr() warning

[...]

Here is the summary with links:
- [iproute2,1/3] json_print: fix Gcc-17 warnings

    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=9361f61abb6d
  - [iproute2,2/3] lib: fix warning from ll_addr_a2n
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=5faf18f672c1
  - [iproute2,3/3] tc/f_u32: fix const strchr() warning
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=21a61425cb9a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html