eldarkg / emdr1986x-std-per-lib

Milandr MCU 1986x Standard Peripherals Library. Mirror:
https://code.launchpad.net/~eldar/emdr1986x-std-per-lib/+git/emdr1986x-std-per-lib
47 stars 28 forks source link

Warning: integer operation result is out of range #49

Closed Amomum closed 5 years ago

Amomum commented 6 years ago

In file MDR32F9Qx_rst_clk.c in function RST_CLK_PCLKcmd:

assert_param(IS_RST_CLK_PCLK(RST_CLK_PCLK));

If USE_ASSERT_INFOis set to 1 or 2, this expands to the following:

((((((RST_CLK_PCLK) & ((uint32_t)(1 << ((((uint32_t)0x40048000) >> 15) & 0x1F)))) == 0x00) && 
(((RST_CLK_PCLK) & ((uint32_t)(1 << ((((uint32_t)0x400D0000) >> 15) & 0x1F)))) == 0x00) && 
(((RST_CLK_PCLK) & ((uint32_t)(1 << ((((uint32_t)0x400E0000) >> 15) & 0x1F)))) == 0x00) && 
(((RST_CLK_PCLK) & ((uint32_t)(1 << ((((uint32_t)0x400F8000) >> 15) & 0x1F)))) == 0x00))) ? (void)0 : assert_failed(4, 1426));

That last check boils down to (1 << 0x1F) and that triggers a warning because 1 is signed int and that shift touches the sign bit.

This shift comes form macro PCLK_BIT:

#define PCLK_BIT(BASE)              ((uint32_t)(1 << ((((uint32_t)BASE) >> 15) & 0x1F)))

Solution is simple, we need to change 1 to 1u.

eldarkg commented 5 years ago

@Amomum Thank you