diff --git a/sys/bitfield/bitfield.c b/sys/bitfield/bitfield.c index bb33165805..c685e28d8d 100644 --- a/sys/bitfield/bitfield.c +++ b/sys/bitfield/bitfield.c @@ -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); } } diff --git a/sys/include/bitfield.h b/sys/include/bitfield.h index 087597d5ab..19c952eb8c 100644 --- a/sys/include/bitfield.h +++ b/sys/include/bitfield.h @@ -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