Re: [RFC PATCH] libbpf: Change hash_combine parameters from long to __u32
From: Andrii Nakryiko
Date: Fri Nov 15 2024 - 14:59:15 EST
On Fri, Nov 15, 2024 at 2:51 AM Sidong Yang <sidong.yang@xxxxxxxxxx> wrote:
>
> The hash_combine() could be trapped when compiled with sanitizer like "zig cc".
> This patch changes parameters to __u32 to fix it.
Can you please elaborate? What exactly are you fixing? "Undefined"
signed integer overflow? I can consider changing long to unsigned
long, but I don't think we should downgrade from long all the way to
32-bit u32. I'd rather keep all those 64 bits for hash.
pw-bot: cr
>
> Signed-off-by: Sidong Yang <sidong.yang@xxxxxxxxxx>
> ---
> tools/lib/bpf/btf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index 8befb8103e32..11ccb5aa4958 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -3548,7 +3548,7 @@ struct btf_dedup {
> struct strset *strs_set;
> };
>
> -static long hash_combine(long h, long value)
> +static __u32 hash_combine(__u32 h, __u32 value)
> {
> return h * 31 + value;
> }
> --
> 2.42.0
>
>