[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAEf4Bzaxp5c9SpUO_aecpPeXqUEy4JwQzqWyKHpY36PtvXKkNw@mail.gmail.com>
Date: Fri, 6 Dec 2024 10:42:45 -0800
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: liujing <liujing@...s.chinamobile.com>
Cc: ast@...nel.org, daniel@...earbox.net, davem@...emloft.net, kuba@...nel.org,
hawk@...nel.org, john.fastabend@...il.com, andrii@...nel.org,
martin.lau@...ux.dev, eddyz87@...il.com, song@...nel.org,
yonghong.song@...ux.dev, kpsingh@...nel.org, sdf@...ichev.me,
haoluo@...gle.com, jolsa@...nel.org, netdev@...r.kernel.org,
bpf@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] samples/bpf: Modify the incorrect format specifier
On Thu, Dec 5, 2024 at 6:31 PM liujing <liujing@...s.chinamobile.com> wrote:
>
> Replace %d with %u in snprintf() because it is "unsigned int".
The code change is fine, but the explanation is ambiguous and hard to
follow. Just mention that we are printing integers, so we need %d
instead of %u for snprintf. As you wrote it above, it reads as if we
are printing unsigned int, yet code contradicts that.
pw-bot: cr
>
> Signed-off-by: liujing <liujing@...s.chinamobile.com>
>
> diff --git a/samples/bpf/xdp_router_ipv4_user.c b/samples/bpf/xdp_router_ipv4_user.c
> index 266fdd0b025d..3fc1d37fee7c 100644
> --- a/samples/bpf/xdp_router_ipv4_user.c
> +++ b/samples/bpf/xdp_router_ipv4_user.c
> @@ -134,11 +134,11 @@ static void read_route(struct nlmsghdr *nh, int nll)
> *((__be32 *)RTA_DATA(rt_attr)));
> break;
> case RTA_OIF:
> - sprintf(ifs, "%u",
> + sprintf(ifs, "%d",
> *((int *)RTA_DATA(rt_attr)));
> break;
> case RTA_METRICS:
> - sprintf(metrics, "%u",
> + sprintf(metrics, "%d",
> *((int *)RTA_DATA(rt_attr)));
> default:
> break;
> --
> 2.27.0
>
>
>
Powered by blists - more mailing lists