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 2EB5841C5F; Fri, 10 Feb 2023 12:26:18 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 73BEC42670; Fri, 10 Feb 2023 12:26:17 +0100 (CET) Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by mails.dpdk.org (Postfix) with ESMTP id 5B02240EE6 for ; Fri, 10 Feb 2023 12:26:16 +0100 (CET) Received: by mail-wr1-f42.google.com with SMTP id j25so4756423wrc.4 for ; Fri, 10 Feb 2023 03:26:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=T8F8ACo6KNuc1MvwTJjv4jiLc7orMQFnp8gg8W+H9Ls=; b=J8yvlQzZiM2UH9pjnz7jStVQC0RfjipZoths6AndMPgEOhDDkGfiBYhQhC+pdOrWFZ 2bBUlCbzBkS04hntdqUn/4iGBno+IJFHYKZBKDbL0BFtFLu5f5SyKsEsxn0kk7Luc6HK AvOPkc1tsakU7WQGUmT34BxuSbemnpovFSsFYLWElqFyYG+G3XI3I4wONZR6Dp80lT1X NHaBjXgTjjtYGGF4fPMHz5jpCWOA8H4xxM5+mPNB3/F8rX1Ft2Jh0qK7KvKrIC1rIuJR 0RRZHwZjxk38HuyG9vn5jd9O59l5DSajx8xrpQYfUzpjEJuyOStufqietseYEyRrvXvZ BP/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=T8F8ACo6KNuc1MvwTJjv4jiLc7orMQFnp8gg8W+H9Ls=; b=T7fhqmop6n+6reat7Bdouh7qJ28NOP2v7uN8yfwoJsPUac0w8MzkkO4t4tRWM790gy Z9olpRWQWza4BVaf5LkgrxrphlJ2Xru7RTCUwIdkRGSWo/2CUsrsr4h3RnwEJPf54c4v Ed4PM4WLH6OKTgdFDZWCToYJo0XPQLRscSZHdQJVsRKWtNzxTMwRcIVsfR6M2gxoFh3b 6pbCsFPzFytYTGbV/XtL0LyuAoqZSctaliYMAoTkEB9yM8msprgjTeTtQ8ZJfdwCT0bq 9tTh7/Lvev6gLRfu3XVLBGSz6/skAFq3/4/rUFn+iLl70WgTYr8aw8gx+jqmUMKGDrCL zdMw== X-Gm-Message-State: AO0yUKUVPREelkDjTfaOASAXxkstEpddJ1ggVQjnj4eP4XTBh/3SPvLc FV+YHAirwQXCIYGISpukEuSZMg== X-Google-Smtp-Source: AK7set8WnA1vqg34x4pAFMxkfFTgYZvvUTOrphMdQe2Si5B6jM9hldFgVEslo28Q6ChCxzQ17V76CQ== X-Received: by 2002:adf:ffd0:0:b0:2c4:695:d644 with SMTP id x16-20020adfffd0000000b002c40695d644mr6932824wrs.9.1676028375994; Fri, 10 Feb 2023 03:26:15 -0800 (PST) Received: from 6wind.com ([2a01:e0a:5ac:6460:c065:401d:87eb:9b25]) by smtp.gmail.com with ESMTPSA id f4-20020a5d6644000000b002bc7e5a1171sm3385485wrw.116.2023.02.10.03.26.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 03:26:15 -0800 (PST) Date: Fri, 10 Feb 2023 12:26:14 +0100 From: Olivier Matz To: Bruce Richardson Cc: Ferruh Yigit , dev@dpdk.org, stable@dpdk.org Subject: Re: [PATCH] examples/cmdline: fix build error with gcc 12 Message-ID: References: <20230118161111.11710-1-bruce.richardson@intel.com> <3dbc9f6b-9efe-5855-aa8c-37513d823db3@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Hi, Sorry for the late reply. On Thu, Jan 19, 2023 at 08:59:10AM +0000, Bruce Richardson wrote: > On Wed, Jan 18, 2023 at 06:53:33PM +0000, Ferruh Yigit wrote: > > On 1/18/2023 4:11 PM, Bruce Richardson wrote: > > > When building the example without libbsd and using the DPDK-provided > > > strlcpy function, a compiler warning is emitted by GCC 12 about the copy > > > of the parsed string into the resulting object. This is because the > > > source from cmdline library is 128 bytes and the destination buffer is > > > 64-bytes. > > > > > > commands.c: In function 'cmd_obj_add_parsed': > > > .../__BUILDS/build-x86-generic/install/usr/local/include/rte_string_fns.h:61:24: warning: '%s' directive output may be truncated writing up to 127 bytes into a region of size 64 [-Wformat-truncation=] > > > 61 | return (size_t)snprintf(dst, size, "%s", src); > > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > In file included from /usr/include/stdio.h:894, > > > from commands.c:7: > > > /usr/include/x86_64-linux-gnu/bits/stdio2.h:71:10: note: '__builtin_snprintf' output between 1 and 128 bytes into a destination of size 64 > > > > > > Multiple options are possible to fix this, but the one taken in this > > > patch is to ensure truncation never occurs by setting the destination > > > buffer size to be the same as that used by the cmdline library. > > > > > > Fixes: af75078fece3 ("first public release") > > > Cc: stable@dpdk.org > > > > > > Signed-off-by: Bruce Richardson > > > --- > > > examples/cmdline/parse_obj_list.h | 3 ++- > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > diff --git a/examples/cmdline/parse_obj_list.h b/examples/cmdline/parse_obj_list.h > > > index 6516d3e2c2..1223ac1e8b 100644 > > > --- a/examples/cmdline/parse_obj_list.h > > > +++ b/examples/cmdline/parse_obj_list.h > > > @@ -12,8 +12,9 @@ > > > > > > #include > > > #include > > > +#include > > > > > > -#define OBJ_NAME_LEN_MAX 64 > > > +#define OBJ_NAME_LEN_MAX sizeof(cmdline_fixed_string_t) > > > > > > struct object { > > > SLIST_ENTRY(object) next; > > > > I confirm it solves the build warning, but what about to get rid of > > `OBJ_NAME_LEN_MAX` completely if the intentions is to make size same as > > cmdline library array: > > > Sure. > Another potential fix is just to cast-away [(void)] the return value from > strlcpy and allow truncation. > > Olivier, as maintainer, what is your preferred fix here? I think you solution is good enough, given it's a dummy example. Acked-by: Olivier Matz Ferruh's comment about getting rid of OBJ_NAME_LEN_MAX is right, however I think in this case we should allocate the string and store a pointer to this string instead of having a size limited buffer. Olivier