[PATCH v4 18/22] net: fix IPv4 macro with highest bit
Konstantin Ananyev
konstantin.ananyev at huawei.com
Wed Jul 16 16:32:47 CEST 2025
> Without an explicit type, all parameters of this macro are considered as
> a signed integer.
>
> ../app/test/test_fib.c:270:20: runtime error: left shift of
> 128 by 24 places cannot be represented in type 'int'
> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
> ../app/test/test_fib.c:270:20 in
>
> Signed-off-by: David Marchand <david.marchand at redhat.com>
> ---
> lib/net/rte_ip4.h | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/lib/net/rte_ip4.h b/lib/net/rte_ip4.h
> index d4b38c513c..822a660cfb 100644
> --- a/lib/net/rte_ip4.h
> +++ b/lib/net/rte_ip4.h
> @@ -65,10 +65,8 @@ struct __rte_aligned(2) __rte_packed_begin rte_ipv4_hdr {
> } __rte_packed_end;
>
> /** Create IPv4 address */
> -#define RTE_IPV4(a, b, c, d) ((uint32_t)(((a) & 0xff) << 24) | \
> - (((b) & 0xff) << 16) | \
> - (((c) & 0xff) << 8) | \
> - ((d) & 0xff))
> +#define RTE_IPV4(a, b, c, d) (((uint32_t)((a) & 0xff) << 24) | ((uint32_t)((b) & 0xff) << 16) | \
> + ((uint32_t)((c) & 0xff) << 8) | ((uint32_t)((d) & 0xff)))
>
> /** Maximal IPv4 packet length (including a header) */
> #define RTE_IPV4_MAX_PKT_LEN 65535
> --
Acked-by: Konstantin Ananyev <konstantin.ananyev at huawei.com>
> 2.50.0
More information about the dev
mailing list