Page 1 of 1

Range check off by one in nvic.c

Posted: Wed Dec 16, 2015 8:47 am
by michael_s
Hello all,

a code checker found the following minimal bug in ..\hal\ports\common\ARMCMx\nvic.c:

Code: Select all

/**
 * @brief   Changes the priority of a system handler.
 *
 * @param[in] handler   the system handler number
 * @param[in] prio      the system handler priority
 */
void nvicSetSystemHandlerPriority(uint32_t handler, uint32_t prio) {

  osalDbgCheck(handler <= 12U);

#if defined(__CORE_CM0_H_GENERIC)
  SCB->SHP[_SHP_IDX(handler)] = (SCB->SHP[_SHP_IDX(handler)] & ~(0xFFU << _BIT_SHIFT(handler))) |
                                (NVIC_PRIORITY_MASK(prio) << _BIT_SHIFT(handler));
#elif defined(__CORE_CM7_H_GENERIC)
  SCB->SHPR[handler] = NVIC_PRIORITY_MASK(prio);
#else
  SCB->SHP[handler] = NVIC_PRIORITY_MASK(prio);
#endif
}


The line

Code: Select all

osalDbgCheck(handler <= 12U);
should be

Code: Select all

osalDbgCheck(handler < 12U);
at least in conjunction with core_cm*.h where

Code: Select all

SHP[12]
is defined.

Kind Regards
Michael

Re: Range check off by one in nvic.c

Posted: Wed Dec 16, 2015 9:45 am
by Giovanni
Fixed, thanks.

Giovanni