analogdevicesinc / msdk

Software Development Kit for Analog Device's MAX-series microcontrollers
Apache License 2.0
60 stars 75 forks source link

Protential bug of MAX_ASSERT usage #1017

Closed TerryWoo123 closed 1 month ago

TerryWoo123 commented 1 month ago

I found this line in in tmr_me16.c, Maybe there are similar lines in other files, for other peripherals or for other parts. MXC_ASSERT((tmr_id = MXC_TMR_GET_IDX(tmr)) >= 0)

if max_assert feature is enabled by MXC_ASSERT_ENABLE, there is no bug. if MXC_ASSERT_ENABLE is not enabled, bug would be occurred. No matter what value tmr is, tmr_id will not be assigned a value, default value 0 will be wrongly used for the resting initialization steps.

I found some examples code in Keil IDE that, MXC_ASSERT_ENABLE is not enabled. the code doesn't run well. the right usage is also already exsiting in MSDK,as below:

    tmr_id = MXC_TMR_GET_IDX(tmr);
        MXC_ASSERT(tmr_id >= 0);

please help to update all the risky lines.

EricB-ADI commented 1 month ago

@TerryWoo123 Thanks I am adding this fix into #1020