Skip to content

Commit 4d1014f

Browse files
committed
check pin range first thing in pinMode(), digitalWrite() and digitalRead()
Signed-off-by: russmcinnis <[email protected]>
1 parent 285ec17 commit 4d1014f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

cores/arduino/wiring_digital.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2626

2727
void pinMode( uint8_t pin, uint8_t mode )
2828
{
29+
if (pin >= NUM_DIGITAL_PINS) return;
30+
2931
PinDescription *p = &g_APinDescription[pin];
3032

3133
if (mode == OUTPUT) {
@@ -60,9 +62,9 @@ void pinMode( uint8_t pin, uint8_t mode )
6062

6163
void digitalWrite( uint8_t pin, uint8_t val )
6264
{
63-
PinDescription *p = &g_APinDescription[pin];
64-
6565
if (pin >= NUM_DIGITAL_PINS) return;
66+
67+
PinDescription *p = &g_APinDescription[pin];
6668

6769
if (!p->ulInputMode) {
6870
if (p->ulGPIOType == SS_GPIO) {
@@ -89,9 +91,9 @@ void digitalWrite( uint8_t pin, uint8_t val )
8991

9092
int digitalRead( uint8_t pin )
9193
{
92-
PinDescription *p = &g_APinDescription[pin];
93-
9494
if (pin >= NUM_DIGITAL_PINS) return LOW;
95+
96+
PinDescription *p = &g_APinDescription[pin];
9597

9698
if (p->ulGPIOType == SS_GPIO)
9799
{

0 commit comments

Comments
 (0)