DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andre Muezerie <andremue@linux.microsoft.com>
To: Bruce Richardson <bruce.richardson@intel.com>
Cc: dev@dpdk.org, Chengwen Feng <fengchengwen@huawei.com>
Subject: Re: [PATCH v2 03/10] test-pmd: fix printf format string mismatch
Date: Tue, 18 Feb 2025 09:03:01 -0800	[thread overview]
Message-ID: <20250218170300.GA6575@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> (raw)
In-Reply-To: <Z7S5gGEGpNqwoctj@bricha3-mobl1.ger.corp.intel.com>

On Tue, Feb 18, 2025 at 04:46:56PM +0000, Bruce Richardson wrote:
> On Tue, Feb 18, 2025 at 08:32:02AM -0800, Andre Muezerie wrote:
> > Compiling with MSVC results in warnings like the one below:
> > 
> > app/test-pmd/csumonly.c(1085): warning C4477: 'printf' : format string
> >     '%d' requires an argument of type 'int',
> >     but variadic argument 1 has type 'uint64_t'
> > 
> > Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
> > Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
> > ---
> >  app/test-pmd/csumonly.c | 23 ++++++++++++-----------
> >  1 file changed, 12 insertions(+), 11 deletions(-)
> > 
> > diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
> > index d77a140641..8de5ad6ad9 100644
> > --- a/app/test-pmd/csumonly.c
> > +++ b/app/test-pmd/csumonly.c
> > @@ -1070,7 +1070,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
> >  				info.l2_len, rte_be_to_cpu_16(info.ethertype),
> >  				info.l3_len, info.l4_proto, info.l4_len, buf);
> >  			if (rx_ol_flags & RTE_MBUF_F_RX_LRO)
> > -				printf("rx: m->lro_segsz=%u\n", m->tso_segsz);
> > +				printf("rx: m->lro_segsz=%" PRIu64 "\n", (uint64_t)m->tso_segsz);
> 
> tso_segsz is already uint64_t, so no need for the cast.

The compilers differ in behavior here. tso_segsz only uses 16 bits of the uint64_t,
and gcc tries to be smart about it and implicitly converts tso_segsz into an int
(since it fits into an int). Msvc does not do that, and keeps the type for tso_segsz
as uint64_t. To support both compilers it seems there's no way to avoid the cast.

> 
> >  			if (info.is_tunnel == 1)
> >  				printf("rx: outer_l2_len=%d outer_ethertype=%x "
> >  					"outer_l3_len=%d\n", info.outer_l2_len,
> > @@ -1082,28 +1082,29 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
> >  					    RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
> >  					    RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) ||
> >  				info.tso_segsz != 0)
> > -				printf("tx: m->l2_len=%d m->l3_len=%d "
> > -					"m->l4_len=%d\n",
> > -					m->l2_len, m->l3_len, m->l4_len);
> > +				printf("tx: m->l2_len=%" PRIu64 " m->l3_len=%" PRIu64
> > +					" m->l4_len=%" PRIu64 "\n",
> > +					(uint64_t)m->l2_len, (uint64_t)m->l3_len,
> > +					(uint64_t)m->l4_len);
> 
> Same here, using casts and a changed print format seems wrong in the patch.
> Either we change the format string to match the variable type, or we cast
> the variables to match the format string. We should not do both, IMHO.

I also normally prefer to not see unnecessary casts in the code, but it looks like
it is needed in this case, as explained above.

> 
> >  			if (info.is_tunnel == 1) {
> >  				if ((tx_offloads &
> >  				    RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ||
> >  				    (tx_offloads &
> >  				    RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ||
> >  				    (tx_ol_flags & RTE_MBUF_F_TX_OUTER_IPV6))
> > -					printf("tx: m->outer_l2_len=%d "
> > -						"m->outer_l3_len=%d\n",
> > -						m->outer_l2_len,
> > -						m->outer_l3_len);
> > +					printf("tx: m->outer_l2_len=%" PRIu64
> > +						" m->outer_l3_len=%" PRIu64 "\n",
> > +						(uint64_t)m->outer_l2_len,
> > +						(uint64_t)m->outer_l3_len);
> >  				if (info.tunnel_tso_segsz != 0 &&
> >  						(m->ol_flags & (RTE_MBUF_F_TX_TCP_SEG |
> >  							RTE_MBUF_F_TX_UDP_SEG)))
> > -					printf("tx: m->tso_segsz=%d\n",
> > -						m->tso_segsz);
> > +					printf("tx: m->tso_segsz=%" PRIu64 "\n",
> > +						(uint64_t)m->tso_segsz);
> >  			} else if (info.tso_segsz != 0 &&
> >  					(m->ol_flags & (RTE_MBUF_F_TX_TCP_SEG |
> >  						RTE_MBUF_F_TX_UDP_SEG)))
> > -				printf("tx: m->tso_segsz=%d\n", m->tso_segsz);
> > +				printf("tx: m->tso_segsz=%" PRIu64 "\n", (uint64_t)m->tso_segsz);
> >  			rte_get_tx_ol_flag_list(m->ol_flags, buf, sizeof(buf));
> >  			printf("tx: flags=%s", buf);
> >  			printf("\n");
> > -- 
> > 2.48.1.vfs.0.0
> > 

  reply	other threads:[~2025-02-18 17:03 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-11 22:01 [PATCH 00/10] enable "app" to be compiled with MSVC Andre Muezerie
2025-02-11 22:01 ` [PATCH 01/10] eal: add workaround for __builtin_constant_p Andre Muezerie
2025-02-11 22:09   ` Stephen Hemminger
2025-02-12  0:59   ` fengchengwen
2025-02-11 22:01 ` [PATCH 02/10] test_alarm: avoid warning about different qualifiers Andre Muezerie
2025-02-12  0:59   ` fengchengwen
2025-02-11 22:01 ` [PATCH 03/10] test-pmd: fix printf format string mismatch Andre Muezerie
2025-02-11 22:10   ` Stephen Hemminger
2025-02-12  1:01   ` fengchengwen
2025-02-11 22:02 ` [PATCH 04/10] test-pmd: do explicit 64-bit shift to avoid implicit conversion Andre Muezerie
2025-02-12  1:03   ` fengchengwen
2025-02-11 22:02 ` [PATCH 05/10] test-pmd: avoid undefined behavior Andre Muezerie
2025-02-12  1:04   ` fengchengwen
2025-02-11 22:02 ` [PATCH 06/10] test-pmd: avoid non-constant initializer Andre Muezerie
2025-02-12  1:04   ` fengchengwen
2025-02-11 22:02 ` [PATCH 07/10] test-pmd: don't return value from void function Andre Muezerie
2025-02-12  1:10   ` fengchengwen
2025-02-11 22:02 ` [PATCH 08/10] test-pmd: declare lcore_count atomic when using C11 memory model Andre Muezerie
2025-02-11 22:12   ` Stephen Hemminger
2025-02-12  1:16     ` Andre Muezerie
2025-02-12  1:16   ` fengchengwen
2025-02-11 22:02 ` [PATCH 09/10] test: add workaround for __builtin_constant_p in test_memcpy_perf Andre Muezerie
2025-02-11 22:13   ` Stephen Hemminger
2025-02-12  2:07     ` Andre Muezerie
2025-02-18 15:35 ` [PATCH 00/10] enable "app" to be compiled with MSVC David Marchand
2025-02-18 16:31 ` [PATCH v2 " Andre Muezerie
2025-02-18 16:32   ` [PATCH v2 01/10] eal: add workaround for __builtin_constant_p Andre Muezerie
2025-02-18 17:12     ` Morten Brørup
2025-02-19 16:50       ` Andre Muezerie
2025-02-19 17:10         ` Stephen Hemminger
2025-02-20  1:59           ` Andre Muezerie
2025-02-18 16:32   ` [PATCH v2 02/10] test_alarm: avoid warning about different qualifiers Andre Muezerie
2025-02-18 16:32   ` [PATCH v2 03/10] test-pmd: fix printf format string mismatch Andre Muezerie
2025-02-18 16:46     ` Bruce Richardson
2025-02-18 17:03       ` Andre Muezerie [this message]
2025-02-18 17:07         ` Bruce Richardson
2025-02-19 17:08           ` Andre Muezerie
2025-02-18 16:32   ` [PATCH v2 04/10] test-pmd: do explicit 64-bit shift to avoid implicit conversion Andre Muezerie
2025-02-18 16:47     ` Bruce Richardson
2025-02-18 16:32   ` [PATCH v2 05/10] test-pmd: avoid undefined behavior Andre Muezerie
2025-02-18 16:41     ` Bruce Richardson
2025-02-19 17:09       ` Andre Muezerie
2025-02-18 16:32   ` [PATCH v2 06/10] test-pmd: avoid non-constant initializer Andre Muezerie
2025-02-18 16:32   ` [PATCH v2 07/10] test-pmd: don't return value from void function Andre Muezerie
2025-02-18 16:42     ` Bruce Richardson
2025-02-18 16:32   ` [PATCH v2 08/10] test-pmd: declare lcore_count atomic Andre Muezerie
2025-02-18 16:32   ` [PATCH v2 09/10] test: add workaround for __builtin_constant_p in test_memcpy_perf Andre Muezerie
2025-02-18 16:32   ` [PATCH v2 10/10] app: enable app directory to be compiled with MSVC Andre Muezerie
2025-02-18 16:49     ` Bruce Richardson
2025-02-19  9:15     ` David Marchand
2025-02-19 14:51       ` Andre Muezerie
2025-02-20  2:01 ` [PATCH v3 00/10] enable "app" " Andre Muezerie
2025-02-20  2:01   ` [PATCH v3 01/10] eal: add workaround for __builtin_constant_p Andre Muezerie
2025-02-20  2:27     ` Stephen Hemminger
2025-02-20  2:01   ` [PATCH v3 02/10] test_alarm: avoid warning about different qualifiers Andre Muezerie
2025-02-20  2:01   ` [PATCH v3 03/10] test-pmd: fix printf format string mismatch Andre Muezerie
2025-02-20  2:01   ` [PATCH v3 04/10] test-pmd: do explicit 64-bit shift to avoid implicit conversion Andre Muezerie
2025-02-20  2:01   ` [PATCH v3 05/10] test-pmd: avoid undefined behavior Andre Muezerie
2025-02-20  2:01   ` [PATCH v3 06/10] test-pmd: avoid non-constant initializer Andre Muezerie
2025-02-20  2:01   ` [PATCH v3 07/10] test-pmd: don't return value from void function Andre Muezerie
2025-02-20  2:01   ` [PATCH v3 08/10] test-pmd: declare lcore_count atomic Andre Muezerie
2025-02-20  2:01   ` [PATCH v3 09/10] test: add workaround for __builtin_constant_p in test_memcpy_perf Andre Muezerie
2025-02-20  2:01   ` [PATCH v3 10/10] app: enable app directory to be compiled with MSVC Andre Muezerie
2025-02-20  7:57   ` [PATCH v3 00/10] enable "app" " Morten Brørup
2025-02-20 21:30 ` [PATCH v4 " Andre Muezerie
2025-02-20 21:30   ` [PATCH v4 01/10] eal: add workaround for __builtin_constant_p Andre Muezerie
2025-02-21 15:31     ` Morten Brørup
2025-02-21 16:47       ` Andre Muezerie
2025-02-20 21:30   ` [PATCH v4 02/10] test_alarm: avoid warning about different qualifiers Andre Muezerie
2025-02-20 21:30   ` [PATCH v4 03/10] test-pmd: fix printf format string mismatch Andre Muezerie
2025-02-21  9:10     ` Bruce Richardson
2025-02-20 21:30   ` [PATCH v4 04/10] test-pmd: do explicit 64-bit shift to avoid implicit conversion Andre Muezerie
2025-02-20 21:30   ` [PATCH v4 05/10] test-pmd: avoid undefined behavior Andre Muezerie
2025-02-20 21:31   ` [PATCH v4 06/10] test-pmd: avoid non-constant initializer Andre Muezerie
2025-02-20 21:31   ` [PATCH v4 07/10] test-pmd: don't return value from void function Andre Muezerie
2025-02-20 21:31   ` [PATCH v4 08/10] test-pmd: declare lcore_count atomic Andre Muezerie
2025-02-21  8:40     ` Konstantin Ananyev
2025-02-20 21:31   ` [PATCH v4 09/10] test: add workaround for __builtin_constant_p in test_memcpy_perf Andre Muezerie
2025-02-20 21:31   ` [PATCH v4 10/10] app: enable app directory to be compiled with MSVC Andre Muezerie
2025-02-20 21:44   ` [PATCH v4 00/10] enable "app" " Stephen Hemminger

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=20250218170300.GA6575@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net \
    --to=andremue@linux.microsoft.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=fengchengwen@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).