diff mbox series

Kselftest: msg_oob.c: Fix warning for Incorrect Specifier

Message ID 20240813060036.754213-1-david.hunter.linux@gmail.com (mailing list archive)
State Not Applicable
Delegated to: Netdev Maintainers
Headers show
Series Kselftest: msg_oob.c: Fix warning for Incorrect Specifier | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 7 this patch: 7
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch warning WARNING: line length of 104 exceeds 80 columns WARNING: line length of 96 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

David Hunter Aug. 13, 2024, 5:59 a.m. UTC
Change specifier to %p to correctly substitute type 'const void *'. A
specifer involved with a macro is causing a misleading warning to occur:

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);
      |                 ^~~~~~

A second set of these three warnings occur later for the incorrect
specifier at msg_oob.c:256. By tracing the various macros involved, the
correct specifier (in msg_oob.c) can be spotted and changed.

Signed-off-by: David Hunter <david.hunter.linux@gmail.com>
---
 tools/testing/selftests/net/af_unix/msg_oob.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Kuniyuki Iwashima Aug. 13, 2024, 6:12 a.m. UTC | #1
From: David Hunter <david.hunter.linux@gmail.com>
Date: Tue, 13 Aug 2024 01:59:57 -0400
> Change specifier to %p to correctly substitute type 'const void *'. A
> specifer involved with a macro is causing a misleading warning to occur:

You may want to run the test before/after the patch.

This is the 3rd patch posted for this warning, so it would be nice to
check lore before posting if the patch/issue is simple enough :)

And here's the correct fix.
https://lore.kernel.org/netdev/20240812191122.1092806-1-jain.abhinav177@gmail.com/

Thanks !
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/af_unix/msg_oob.c b/tools/testing/selftests/net/af_unix/msg_oob.c
index 16d0c172eaeb..87090ebda2a7 100644
--- a/tools/testing/selftests/net/af_unix/msg_oob.c
+++ b/tools/testing/selftests/net/af_unix/msg_oob.c
@@ -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:%p", expected_errno ? strerror(expected_errno) : 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:%p", expected_errno ? strerror(expected_errno) : expected_buf);
 
 			ASSERT_EQ(cmp, 0);
 		}