1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-28 22:29:45 +01:00

sys/bitfield: don't set unrelated bits in bf_{set, clear}_all()

This commit is contained in:
Benjamin Valentin 2023-03-16 16:39:30 +01:00
parent 19ab9c5dc7
commit 2d704a2c59
2 changed files with 13 additions and 5 deletions

View File

@ -90,7 +90,18 @@ void bf_set_all(uint8_t field[], size_t size)
memset(field, 0xff, bytes);
if (bits) {
field[bytes] = ~((1U << (8 - bits)) - 1);
field[bytes] |= ~((1U << (8 - bits)) - 1);
}
}
void bf_clear_all(uint8_t field[], size_t size)
{
unsigned bytes = size >> 3;
unsigned bits = size & 0x7;
memset(field, 0, bytes);
if (bits) {
field[bytes] &= ((1U << (8 - bits)) - 1);
}
}

View File

@ -365,10 +365,7 @@ static inline void bf_set_all_atomic(uint8_t field[], size_t size)
* @param[in] field The bitfield
* @param[in] size The number of bits in the bitfield
*/
static inline void bf_clear_all(uint8_t field[], size_t size)
{
memset(field, 0, (size + 7) / 8);
}
void bf_clear_all(uint8_t field[], size_t size);
/**
* @brief Atomically clear all bits in the bitfield to 0