Re: [PATCH] samples/bpf: Modify the incorrect format specifier
From: Andrii Nakryiko
Date: Fri Dec 06 2024 - 13:43:10 EST
On Thu, Dec 5, 2024 at 6:31 PM liujing <liujing@xxxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxxxxxxxx>
>
> 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
>
>
>