diff options
author | Jere Leppänen <jere.leppanen@nokia.com> | 2024-03-20 10:36:23 +0200 |
---|---|---|
committer | Matias Elo <matias.elo@nokia.com> | 2024-04-16 16:49:46 +0300 |
commit | 3f6ca9ce241b1f02bf60c72337b03f7fda7e6c6b (patch) | |
tree | 34db973806f3d1063de325fc6d6b0aee316eea27 | |
parent | fa692a0ac8f26e37efef788174ea5e8349d0fcc8 (diff) |
test: performance: pktio_ordered: avoid undefined behavior in bit shift in calc_ipv4_5tuple_hash()
Avoid undefined behavior in bit shift in calc_ipv4_5tuple_hash() by
casting to an unsigned integer of sufficient width before the shift
operation.
Fixes GCC undefined sanitizer error:
odp_pktio_ordered.c:336:24: runtime error: left shift of negative value -25535
Also, use unsigned types in ipv4_tuple5_t. This avoids potential
implementation defined results in calc_flow_idx() when assigning
unsigned values to a tuple.
Signed-off-by: Jere Leppänen <jere.leppanen@nokia.com>
Reviewed-by: Janne Peltonen <janne.peltonen@nokia.com>
-rw-r--r-- | test/performance/odp_pktio_ordered.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/test/performance/odp_pktio_ordered.c b/test/performance/odp_pktio_ordered.c index 73745e115..18845a5df 100644 --- a/test/performance/odp_pktio_ordered.c +++ b/test/performance/odp_pktio_ordered.c @@ -188,13 +188,13 @@ typedef union ODP_ALIGNED_CACHE { * IPv4 5-tuple */ typedef struct { - int32_t src_ip; - int32_t dst_ip; - int16_t src_port; - int16_t dst_port; - int8_t proto; - int8_t pad0; - int16_t pad1; + uint32_t src_ip; + uint32_t dst_ip; + uint16_t src_port; + uint16_t dst_port; + uint8_t proto; + uint8_t pad0; + uint16_t pad1; } ipv4_tuple5_t; /** @@ -333,7 +333,7 @@ static inline uint64_t calc_ipv4_5tuple_hash(ipv4_tuple5_t *tuple) mix(a, b, c); - a += (tuple->src_port << 16) + tuple->dst_port + JHASH_GOLDEN_RATIO; + a += ((uint32_t)tuple->src_port << 16) + tuple->dst_port + JHASH_GOLDEN_RATIO; final(a, b, c); return c; |