acl: fix undefined behavior of bit shifts
Left-shift of an integer constant is represented as 'int' type, but a left
shift of 1 by 31 bits in 'int' is undefined. Use the U suffix to force
a representation as unsigned.
Caught while running with ubsan under gcc.
Fixes: dc276b5780
("acl: new library")
Cc: stable@dpdk.org
Signed-off-by: Aaron Conole <aconole@redhat.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
This commit is contained in:
parent
786e0c74e6
commit
5924381221
@ -320,7 +320,7 @@ acl_add_ptr_range(struct acl_build_context *context,
|
||||
for (n = 0; n < UINT8_MAX + 1; n++)
|
||||
if (n >= low && n <= high)
|
||||
bitset.bits[n / (sizeof(bits_t) * 8)] |=
|
||||
1 << (n % (sizeof(bits_t) * 8));
|
||||
1U << (n % (sizeof(bits_t) * CHAR_BIT));
|
||||
|
||||
return acl_add_ptr(context, root, node, &bitset);
|
||||
}
|
||||
@ -343,7 +343,7 @@ acl_gen_mask(struct rte_acl_bitset *bitset, uint32_t value, uint32_t mask)
|
||||
if ((n & mask) == value) {
|
||||
range++;
|
||||
bitset->bits[n / (sizeof(bits_t) * 8)] |=
|
||||
1 << (n % (sizeof(bits_t) * 8));
|
||||
1U << (n % (sizeof(bits_t) * CHAR_BIT));
|
||||
}
|
||||
}
|
||||
return range;
|
||||
@ -972,7 +972,7 @@ build_trie(struct acl_build_context *context, struct rte_acl_build_rule *head,
|
||||
sizeof(*end->mrt));
|
||||
|
||||
for (m = context->cfg.num_categories; 0 != m--; ) {
|
||||
if (rule->f->data.category_mask & (1 << m)) {
|
||||
if (rule->f->data.category_mask & (1U << m)) {
|
||||
end->mrt->results[m] = rule->f->data.userdata;
|
||||
end->mrt->priority[m] = rule->f->data.priority;
|
||||
} else {
|
||||
|
@ -133,7 +133,7 @@ acl_node_fill_dfa(const struct rte_acl_node *node,
|
||||
for (n = 0; n < RTE_ACL_DFA_SIZE; n++) {
|
||||
|
||||
if (bits->bits[n / (sizeof(bits_t) * CHAR_BIT)] &
|
||||
(1 << (n % (sizeof(bits_t) * CHAR_BIT)))) {
|
||||
(1U << (n % (sizeof(bits_t) * CHAR_BIT)))) {
|
||||
|
||||
dfa[n] = resolved ? child->node_index : x;
|
||||
ranges += (last_bit == 0);
|
||||
@ -175,7 +175,7 @@ acl_count_sequential_groups(struct rte_acl_bitset *bits, int zero_one)
|
||||
}
|
||||
for (n = 0; n < QRANGE_MIN; n++) {
|
||||
if (bits->bits[n / (sizeof(bits_t) * 8)] &
|
||||
(1 << (n % (sizeof(bits_t) * 8)))) {
|
||||
(1U << (n % (sizeof(bits_t) * CHAR_BIT)))) {
|
||||
if (zero_one == 1 && last_bit != 1)
|
||||
ranges++;
|
||||
last_bit = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user