DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: Ferruh Yigit <ferruh.yigit@amd.com>
Cc: Thomas Monjalon <thomas@monjalon.net>, Ori Kam <orika@nvidia.com>,
	"Andrew Rybchenko" <andrew.rybchenko@oktetlabs.ru>,
	<dev@dpdk.org>
Subject: Re: [RFC] ethdev: convert string initialization
Date: Thu, 1 Aug 2024 11:33:37 +0100	[thread overview]
Message-ID: <Zqtkgbx28G6IHWyX@bricha3-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <20240801092722.3732917-1-ferruh.yigit@amd.com>

On Thu, Aug 01, 2024 at 02:27:22AM -0700, Ferruh Yigit wrote:
> gcc 15 experimental [1], with -Wextra flag, gives warning in variable
> initialization as string [2].
> 
> The warning has a point when initialized variable is intended to use as
> string, since assignment is missing the required null terminator for
> this case. But warning is useless for our usecase.
> 
> I don't know if this behaviour will change in gcc15, as it is still
> under development. But if not we may need to update our initialization.
> 
> In this patch only updated a few instance to show the issue, there are
> many instances to fix, if we prefer to go this way.
> Other option is to disable warning but it can be useful for actual
> string usecases, so I prefer to keep it.
> 
> [1]
> gcc (GCC) 15.0.0 20240801 (experimental)
> 
> [2]
> ../lib/ethdev/rte_flow.h:906:36:
>   error: initializer-string for array of ‘unsigned char’ is too long
>         [-Werror=unterminated-string-initialization]
> 906 |         .hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
>     |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> ../lib/ethdev/rte_flow.h:907:36:
>   error: initializer-string for array of ‘unsigned char’ is too long
>          [-Werror=unterminated-string-initialization]
> 907 |         .hdr.src_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
>     |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> ../lib/ethdev/rte_flow.h:1009:25:
>   error: initializer-string for array of ‘unsigned char’ is too long
>          [-Werror=unterminated-string-initialization]
> 1009 |                         "\xff\xff\xff\xff\xff\xff\xff\xff"
>      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> ../lib/ethdev/rte_flow.h:1012:25:
>   error: initializer-string for array of ‘unsigned char’ is too long
>          [-Werror=unterminated-string-initialization]
> 1012 |                         "\xff\xff\xff\xff\xff\xff\xff\xff"
>      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> ../lib/ethdev/rte_flow.h:1135:20:
>   error: initializer-string for array of ‘unsigned char’ is too long
>          [-Werror=unterminated-string-initialization]
> 1135 |         .hdr.vni = "\xff\xff\xff",
>      |                    ^~~~~~~~~~~~~~
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@amd.com>
> ---
>  lib/ethdev/rte_flow.h | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h
> index f864578f806b..8b623974cd44 100644
> --- a/lib/ethdev/rte_flow.h
> +++ b/lib/ethdev/rte_flow.h
> @@ -903,8 +903,8 @@ struct rte_flow_item_eth {
>  /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */
>  #ifndef __cplusplus
>  static const struct rte_flow_item_eth rte_flow_item_eth_mask = {
> -	.hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
> -	.hdr.src_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
> +	.hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
> +	.hdr.src_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
>  	.hdr.ether_type = RTE_BE16(0x0000),
>  };
>  #endif
> @@ -1005,12 +1005,10 @@ struct rte_flow_item_ipv6 {
>  #ifndef __cplusplus
>  static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
>  	.hdr = {
> -		.src_addr =
> -			"\xff\xff\xff\xff\xff\xff\xff\xff"
> -			"\xff\xff\xff\xff\xff\xff\xff\xff",
> -		.dst_addr =
> -			"\xff\xff\xff\xff\xff\xff\xff\xff"
> -			"\xff\xff\xff\xff\xff\xff\xff\xff",
> +		.src_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
> +			      0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
> +		.dst_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
> +			      0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
>  	},
>  };
>  #endif
> @@ -1132,7 +1130,7 @@ struct rte_flow_item_vxlan {
>  /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
>  #ifndef __cplusplus
>  static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
> -	.hdr.vni = "\xff\xff\xff",
> +	.hdr.vni = { 0xff, 0xff, 0xff },
>  };
>  #endif

This solution LGTM.

Acked-by: Bruce Richardson <bruce.richardson@intel.com>

  reply	other threads:[~2024-08-01 10:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-01  9:27 Ferruh Yigit
2024-08-01 10:33 ` Bruce Richardson [this message]
2024-08-01 11:29 ` Morten Brørup
2024-08-01 12:43   ` Ferruh Yigit
2024-08-01 13:29     ` Morten Brørup
2024-08-06  5:54 ` Tyler Retzlaff

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=Zqtkgbx28G6IHWyX@bricha3-mobl1.ger.corp.intel.com \
    --to=bruce.richardson@intel.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=orika@nvidia.com \
    --cc=thomas@monjalon.net \
    /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).