The following code has an unexpected out-of-bounds array access:
#define DRDY_PIN 24 nrfx_gpiote_in_uninit(DRDY_PIN); nrfx_gpiote_in_init(DRDY_PIN, &drdy_cfg,onDRDY_gpiote_evt);
Primary cause is this line:
channel_free((uint8_t)channel_port_get(pin));
On an uninitalized pin number, channel_port_get() returns -1, which is converted to 255 via the cast and this causes out of bounds access in channel_free() - as the latter function does not check its argument for overflows.
Fix is pretty simple:
static void channel_free(uint8_t channel_id)
{
if (channel_id >=
(GPIOTE_CH_NUM + NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS)) return;
m_cb.handlers[channel_id] = FORBIDDEN_HANDLER_ADDRESS;
Edit: This is using nRF SDK 16.0 version.