From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 95DC545746; Tue, 6 Aug 2024 07:54:58 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 67557402CF; Tue, 6 Aug 2024 07:54:58 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 01576402BA for ; Tue, 6 Aug 2024 07:54:57 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id 2BA2C20B7165; Mon, 5 Aug 2024 22:54:56 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2BA2C20B7165 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1722923696; bh=K11tIpMi7OlYQaE+g+sHxhhsQpKuy0CxricvqhwxrZo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NCvqpJVUpO/pIMe/gSt5qMx5y8f8R3TiFTvHUZNKpvW/l3zn6mBenZDuTpk0iBJRy EkuLnZmlYtns1fvjOCR9+S2tr9ps/v3ImYXbqBgrLceVUEBd0+yWzkHduNDmOh/XRa 8RCpBwrkx1VuKLZ0QpbpZKrjK62btbFxVRuAlGM4= Date: Mon, 5 Aug 2024 22:54:56 -0700 From: Tyler Retzlaff To: Ferruh Yigit Cc: Thomas Monjalon , Ori Kam , Andrew Rybchenko , dev@dpdk.org Subject: Re: [RFC] ethdev: convert string initialization Message-ID: <20240806055456.GC19300@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <20240801092722.3732917-1-ferruh.yigit@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240801092722.3732917-1-ferruh.yigit@amd.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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. i investigated this when msvc had some issues with it as well. we determined that it is actually iso c standard compliant. what basically happens is the characters of the string are copied up to the destination size and any remaining characters from the string literal (including the NUL) are discarded and that is what leads to the warning. yes, the copied bytes lost their NUL terminator but the destination isn't a string so meh, whatever. either way i support your fix, it deals with the problem with msvc as well. thank you! > > 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 > --- > 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 > > -- > 2.43.0