From: Justin Stitt <jstitt007@gmail.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>,
Jozsef Kadlecsik <kadlec@netfilter.org>,
Florian Westphal <fw@strlen.de>
Cc: llvm@lists.linux.dev, Nick Desaulniers <ndesaulniers@google.com>,
Justin Stitt <jstitt007@gmail.com>
Subject: [PATCH] netfilter: conntrack: fix this -Wformat clang warning:
Date: Mon, 6 Jun 2022 14:28:19 -0700 [thread overview]
Message-ID: <20220606212819.9548-1-jstitt007@gmail.com> (raw)
| net/netfilter/nf_conntrack_standalone.c:63:7: warning: format specifies type
| 'unsigned short' but the argument has type 'int' [-Wformat]
| ntohs(tuple->src.u.tcp.port),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| net/netfilter/nf_conntrack_standalone.c:64:7: warning: format specifies type
| 'unsigned short' but the argument has type 'int' [-Wformat]
| ntohs(tuple->dst.u.tcp.port));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| net/netfilter/nf_conntrack_standalone.c:69:7: warning: format specifies type
| 'unsigned short' but the argument has type 'int' [-Wformat]
| ntohs(tuple->src.u.udp.port),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| net/netfilter/nf_conntrack_standalone.c:70:7: warning: format specifies type
| 'unsigned short' but the argument has type 'int' [-Wformat]
| ntohs(tuple->dst.u.udp.port));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| net/netfilter/nf_conntrack_standalone.c:75:7: warning: format specifies type
| 'unsigned short' but the argument has type 'int' [-Wformat]
| ntohs(tuple->src.u.dccp.port),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| net/netfilter/nf_conntrack_standalone.c:76:7: warning: format specifies type
| 'unsigned short' but the argument has type 'int' [-Wformat]
| ntohs(tuple->dst.u.dccp.port));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| net/netfilter/nf_conntrack_standalone.c:80:7: warning: format specifies type
| 'unsigned short' but the argument has type 'int' [-Wformat]
| ntohs(tuple->src.u.sctp.port),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| net/netfilter/nf_conntrack_standalone.c:81:7: warning: format specifies type
| 'unsigned short' but the argument has type 'int' [-Wformat]
| ntohs(tuple->dst.u.sctp.port));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Variadic functions (printf-like) undergo default argument promotion.
Documentation/core-api/printk-formats.rst specifically recommends
using the promoted-to-type's format flag.
Also, as per C11 6.3.1.1:
(https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf)
`If an int can represent all values of the original type ..., the
value is converted to an int; otherwise, it is converted to an
unsigned int. These are called the integer promotions.`
Thus it makes sense to change %hu (as well as %u) to %d.
Signed-off-by: Justin Stitt <jstitt007@gmail.com>
---
net/netfilter/nf_conntrack_standalone.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index 6ad7bbc90d38..afbec8a12c5e 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -53,30 +53,30 @@ print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
switch (l4proto->l4proto) {
case IPPROTO_ICMP:
- seq_printf(s, "type=%u code=%u id=%u ",
+ seq_printf(s, "type=%d code=%d id=%d ",
tuple->dst.u.icmp.type,
tuple->dst.u.icmp.code,
ntohs(tuple->src.u.icmp.id));
break;
case IPPROTO_TCP:
- seq_printf(s, "sport=%hu dport=%hu ",
+ seq_printf(s, "sport=%d dport=%d ",
ntohs(tuple->src.u.tcp.port),
ntohs(tuple->dst.u.tcp.port));
break;
case IPPROTO_UDPLITE:
case IPPROTO_UDP:
- seq_printf(s, "sport=%hu dport=%hu ",
+ seq_printf(s, "sport=%d dport=%d ",
ntohs(tuple->src.u.udp.port),
ntohs(tuple->dst.u.udp.port));
break;
case IPPROTO_DCCP:
- seq_printf(s, "sport=%hu dport=%hu ",
+ seq_printf(s, "sport=%d dport=%d ",
ntohs(tuple->src.u.dccp.port),
ntohs(tuple->dst.u.dccp.port));
break;
case IPPROTO_SCTP:
- seq_printf(s, "sport=%hu dport=%hu ",
+ seq_printf(s, "sport=%d dport=%d ",
ntohs(tuple->src.u.sctp.port),
ntohs(tuple->dst.u.sctp.port));
break;
--
2.30.2
next reply other threads:[~2022-06-06 21:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-06 21:28 Justin Stitt [this message]
2022-06-07 15:27 ` [PATCH] netfilter: conntrack: fix this -Wformat clang warning: Nathan Chancellor
2022-06-07 18:08 ` [PATCH v2] netfilter: conntrack: Fix clang -Wformat warning in print_tuple() Justin Stitt
2022-06-07 20:33 ` Nick Desaulniers
2022-06-07 20:36 ` Nick Desaulniers
2022-06-07 20:35 ` Nathan Chancellor
2022-06-07 20:29 ` [PATCH] netfilter: conntrack: fix this -Wformat clang warning: Nick Desaulniers
2022-06-07 20:46 ` Nathan Chancellor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220606212819.9548-1-jstitt007@gmail.com \
--to=jstitt007@gmail.com \
--cc=fw@strlen.de \
--cc=kadlec@netfilter.org \
--cc=llvm@lists.linux.dev \
--cc=ndesaulniers@google.com \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox