From 700186bcd7c51f127078d86ef1873edcb3239812 Mon Sep 17 00:00:00 2001 From: Norman Dunbar Date: Tue, 21 Aug 2018 20:11:13 +0100 Subject: [PATCH] Fixed issue #25. Possible corruption in attachInterrupt. digitalPinToInterrupt may return NOT_AN_INTERRUPT if an invalid pin given. attachInterrupt and detachInterrupt need to check for this or they risk corrupting memory just before intFunc[]. Please enter the commit message for your changes. Lines starting --- cores/arduino/WInterrupts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/WInterrupts.c b/cores/arduino/WInterrupts.c index cef1106e0..689cd82b8 100644 --- a/cores/arduino/WInterrupts.c +++ b/cores/arduino/WInterrupts.c @@ -68,7 +68,7 @@ static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS] = { // volatile static voidFuncPtr twiIntFunc; void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { - if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { + if((interruptNum < EXTERNAL_NUM_INTERRUPTS) && (interruptNum != NOT_AN_INTERRUPT)) { intFunc[interruptNum] = userFunc; // Configure the interrupt mode (trigger on low input, any change, rising @@ -185,7 +185,7 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { } void detachInterrupt(uint8_t interruptNum) { - if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { + if((interruptNum < EXTERNAL_NUM_INTERRUPTS) && (interruptNum != NOT_AN_INTERRUPT)) { // Disable the interrupt. (We can't assume that interruptNum is equal // to the number of the EIMSK bit to clear, as this isn't true on the // ATmega8. There, INT0 is 6 and INT1 is 7.)