Range check off by one in nvic.c

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
michael_s
Posts: 4
Joined: Thu Dec 03, 2015 3:31 pm
Been thanked: 1 time

Range check off by one in nvic.c

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Range check off by one in nvic.c

Post by Giovanni »

Fixed, thanks.

Giovanni
Post Reply