All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wl@xen.org>
To: Bertrand Marquis <bertrand.marquis@arm.com>
Cc: xen-devel@lists.xenproject.org, jgross@suse.com,
	Ian Jackson <iwj@xenproject.org>, Wei Liu <wl@xen.org>
Subject: Re: [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge
Date: Mon, 5 Oct 2020 16:42:53 +0000	[thread overview]
Message-ID: <20201005164253.cse24pshvbpoehjw@liuwe-devbox-debian-v2> (raw)
In-Reply-To: <3de58159c6fde0cdfa4d0f292fa55fdb931cb3aa.1601913536.git.bertrand.marquis@arm.com>

On Mon, Oct 05, 2020 at 05:02:48PM +0100, Bertrand Marquis wrote:
> Use memcpy in getBridge to prevent gcc warnings about truncated
> strings. We know that we might truncate it, so the gcc warning
> here is wrong.
> Revert previous change changing buffer sizes as bigger buffers
> are not needed.
> 
> Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>

Juergen, are you happy with this change? I have not followed closely the
discussion on #xendevel.

> ---
>  tools/libs/stat/xenstat_linux.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c
> index d2ee6fda64..1db35c604c 100644
> --- a/tools/libs/stat/xenstat_linux.c
> +++ b/tools/libs/stat/xenstat_linux.c
> @@ -78,7 +78,12 @@ static void getBridge(char *excludeName, char *result, size_t resultLen)
>  				sprintf(tmp, "/sys/class/net/%s/bridge", de->d_name);
>  
>  				if (access(tmp, F_OK) == 0) {
> -					strncpy(result, de->d_name, resultLen);
> +					/*
> +					 * Do not use strncpy to prevent compiler warning with
> +					 * gcc >= 10.0
> +					 * If de->d_name is longer then resultLen we truncate it
> +					 */
> +					memcpy(result, de->d_name, resultLen - 1);
>  					result[resultLen - 1] = 0;
>  				}
>  		}
> @@ -264,7 +269,7 @@ int xenstat_collect_networks(xenstat_node * node)
>  {
>  	/* Helper variables for parseNetDevLine() function defined above */
>  	int i;
> -	char line[512] = { 0 }, iface[16] = { 0 }, devBridge[256] = { 0 }, devNoBridge[257] = { 0 };
> +	char line[512] = { 0 }, iface[16] = { 0 }, devBridge[16] = { 0 }, devNoBridge[17] = { 0 };
>  	unsigned long long rxBytes, rxPackets, rxErrs, rxDrops, txBytes, txPackets, txErrs, txDrops;
>  
>  	struct priv_data *priv = get_priv_data(node->handle);
> -- 
> 2.17.1
> 


  reply	other threads:[~2020-10-05 16:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-05 16:02 [PATCH 0/2] tools: solve gcc 10 compilation issues Bertrand Marquis
2020-10-05 16:02 ` [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge Bertrand Marquis
2020-10-05 16:42   ` Wei Liu [this message]
2020-10-06  4:34   ` Jürgen Groß
2020-10-06  7:51     ` Bertrand Marquis
2020-10-06  8:19       ` Jürgen Groß
2020-10-06 15:46         ` Bertrand Marquis
2020-10-05 16:02 ` [PATCH 2/2] tool/libx: Fix libxenlight gcc warning Bertrand Marquis
2020-10-05 16:57   ` Wei Liu

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=20201005164253.cse24pshvbpoehjw@liuwe-devbox-debian-v2 \
    --to=wl@xen.org \
    --cc=bertrand.marquis@arm.com \
    --cc=iwj@xenproject.org \
    --cc=jgross@suse.com \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.