Skip to contentSkip to conversation

selftests: net: af_unix: cast void* to char* in call to macro TH_LOG()

PATCH In review Mirsad Todorovac 3 participants 4 messages Aug 12, 2024 – Aug 13, 2024

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

PATCH 1/1 selftests: net: af_unix: cast void* to char* in call to macro TH_LOG()

GCC 13.2.0 reported warning about (void *) beeing used as a param where (char *) is expected:

In file included from msg_oob.c:14:
msg_oob.c: In function ‘__recvpair’:
../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
but argument 6 has type ‘const void *’ [-Wformat=]

  106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
      |                                        ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
  101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
      |                 ^~~~~~~~
msg_oob.c:235:17: note: in expansion of macro ‘TH_LOG’
  235 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
      |                 ^~~~~~
../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
							but argument 6 has type ‘const void *’ [-Wformat=]
  106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
      |                                        ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
  101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
      |                 ^~~~~~~~
msg_oob.c:259:25: note: in expansion of macro ‘TH_LOG’
  259 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
      |                 ^~~~~~

Casting param to (char *) silences the warning.

Fixes d098d77232c37 ("selftest: af_unix: Add msg_oob.c.")
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Kuniyuki Iwashima <[email protected]>

---
v1:
initial version to fix the compiler warning.

 tools/testing/selftests/net/af_unix/msg_oob.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/net/af_unix/msg_oob.c +2 -2
index 16d0c172eaeb..ae2623eea8ae 100644
@@ -232,7 +232,7 @@ static void __recvpair(struct __test_metadata *_metadata,
 
 	if (ret[0] != expected_len || recv_errno[0] != expected_errno) {
 		TH_LOG("AF_UNIX :%s", ret[0] < 0 ? strerror(recv_errno[0]) : recv_buf[0]);
-		TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
+		TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : (char *)expected_buf);
 
 		ASSERT_EQ(ret[0], expected_len);
 		ASSERT_EQ(recv_errno[0], expected_errno);
@@ -256,7 +256,7 @@ static void __recvpair(struct __test_metadata *_metadata,
 		cmp = strncmp(expected_buf, recv_buf[0], expected_len);
 		if (cmp) {
 			TH_LOG("AF_UNIX :%s", ret[0] < 0 ? strerror(recv_errno[0]) : recv_buf[0]);
-			TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
+			TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : (char *)expected_buf);
 
 			ASSERT_EQ(cmp, 0);
 		}
Signature · 1 line
2.43.0
reviewer
#1 lore raw
Quoted 1 line · Mirsad Todorovac

GCC 13.2.0 reported warning about (void *) beeing used as a param where (char *) is expected:

nit: being

Quoted 15 lines

In file included from msg_oob.c:14:
msg_oob.c: In function ‘__recvpair’:
../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
but argument 6 has type ‘const void *’ [-Wformat=]

  106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
      |                                        ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
  101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
      |                 ^~~~~~~~
msg_oob.c:235:17: note: in expansion of macro ‘TH_LOG’
  235 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
      |                 ^~~~~~

../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
but argument 6 has type ‘const void *’ [-Wformat=]

Quoted 8 lines
  106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
      |                                        ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
  101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
      |                 ^~~~~~~~
msg_oob.c:259:25: note: in expansion of macro ‘TH_LOG’
  259 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
      |                 ^~~~~~

Thanks, I see this too.

Quoted 1 line

Casting param to (char *) silences the warning.

It seems that all callers pass a string as the expected_errno argument. Perhaps it's type could be updated to char *, if that is what it is. I think this would avoid the need to cast.

Quoted 10 lines
Fixes d098d77232c37 ("selftest: af_unix: Add msg_oob.c.")
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Kuniyuki Iwashima <[email protected]>

...

#2 lore raw

Hi, Simon,

Quoted 4 lines · Simon Horman
Quoted 1 line · Mirsad Todorovac

GCC 13.2.0 reported warning about (void *) beeing used as a param where (char *) is expected:

nit: being

Ouch! No patch is small enough that one should take its correctness for granted. :-O

Quoted 23 lines
Quoted 14 lines

In file included from msg_oob.c:14:
msg_oob.c: In function ‘__recvpair’:
../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
but argument 6 has type ‘const void *’ [-Wformat=]

  106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
      |                                        ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
  101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
      |                 ^~~~~~~~
msg_oob.c:235:17: note: in expansion of macro ‘TH_LOG’
  235 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
      |                 ^~~~~~

../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
but argument 6 has type ‘const void *’ [-Wformat=]

Quoted 8 lines
  106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
      |                                        ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
  101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
      |                 ^~~~~~~~
msg_oob.c:259:25: note: in expansion of macro ‘TH_LOG’
  259 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
      |                 ^~~~~~
Quoted 7 lines

Thanks, I see this too.

Quoted 1 line

Casting param to (char *) silences the warning.

It seems that all callers pass a string as the expected_errno argument. Perhaps it's type could be updated to char *, if that is what it is. I think this would avoid the need to cast.

Agreed and verified. If it is OK with you, I might post a v2.

Best regards,
Mirsad Todorovac

Quoted 12 lines
Quoted 10 lines
Fixes d098d77232c37 ("selftest: af_unix: Add msg_oob.c.")
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Kuniyuki Iwashima <[email protected]>

...

#3 lore raw
In reply to Mirsad Todorovac

From: Mirsad Todorovac <[email protected]>
Date: Mon, 12 Aug 2024 02:22:58 +0200

Quoted 27 lines

GCC 13.2.0 reported warning about (void *) beeing used as a param where (char *) is expected:

In file included from msg_oob.c:14:
msg_oob.c: In function ‘__recvpair’:
../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
but argument 6 has type ‘const void *’ [-Wformat=]

  106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
      |                                        ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
  101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
      |                 ^~~~~~~~
msg_oob.c:235:17: note: in expansion of macro ‘TH_LOG’
  235 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
      |                 ^~~~~~
../../kselftest_harness.h:106:40: warning: format ‘%s’ expects argument of type ‘char *’,
							but argument 6 has type ‘const void *’ [-Wformat=]
  106 |                 fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \
      |                                        ^~~~~~~~~~~~~
../../kselftest_harness.h:101:17: note: in expansion of macro ‘__TH_LOG’
  101 |                 __TH_LOG(fmt, ##__VA_ARGS__); \
      |                 ^~~~~~~~
msg_oob.c:259:25: note: in expansion of macro ‘TH_LOG’
  259 |                 TH_LOG("Expected:%s", expected_errno ? strerror(expected_errno) : expected_buf);
      |                 ^~~~~~

Casting param to (char *) silences the warning.

Quoted 10 lines
Fixes d098d77232c37 ("selftest: af_unix: Add msg_oob.c.")
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Kuniyuki Iwashima <[email protected]>

Thanks for the patch!

but I found the same patch posted a bit earlier here, and Abhinav will post v2.

https://lore.kernel.org/netdev/[email protected]/