Skip to content

Commit b8bff65

Browse files
rugeGerritsenkartben
authored andcommitted
include: common: sys_bitops: Specify sign when bitshifting
When left-shifting '1' by 31, the result is undefined. This is something ASAN detects. Solve this by explicitly defining that the integer is unsigned. Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
1 parent e0a915a commit b8bff65

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

include/zephyr/arch/common/sys_bitops.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ static ALWAYS_INLINE void sys_set_bit(mem_addr_t addr, unsigned int bit)
2525
{
2626
uint32_t temp = *(volatile uint32_t *)addr;
2727

28-
*(volatile uint32_t *)addr = temp | (1 << bit);
28+
*(volatile uint32_t *)addr = temp | (1U << bit);
2929
}
3030

3131
static ALWAYS_INLINE void sys_clear_bit(mem_addr_t addr, unsigned int bit)
3232
{
3333
uint32_t temp = *(volatile uint32_t *)addr;
3434

35-
*(volatile uint32_t *)addr = temp & ~(1 << bit);
35+
*(volatile uint32_t *)addr = temp & ~(1U << bit);
3636
}
3737

3838
static ALWAYS_INLINE int sys_test_bit(mem_addr_t addr, unsigned int bit)
3939
{
4040
uint32_t temp = *(volatile uint32_t *)addr;
4141

42-
return temp & (1 << bit);
42+
return temp & (1U << bit);
4343
}
4444

4545
static ALWAYS_INLINE void sys_set_bits(mem_addr_t addr, unsigned int mask)

0 commit comments

Comments
 (0)