Skip to content

Commit 2540172

Browse files
authored
atsam: add a length check to findPinPadMapping
1 parent 0c4f0b1 commit 2540172

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/machine/machine_atsamd21.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ var pinPadMapping = [32]byte{
136136
// found" (indicated by returning ok=false). The pad number is returned to
137137
// calculate the DOPO/DIPO bitfields of the various serial peripherals.
138138
func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok bool) {
139+
if int(pin)/2 >= len(pinPadMapping) {
140+
// This is probably NoPin, for which no mapping is available.
141+
return
142+
}
143+
139144
nibbles := pinPadMapping[pin/2]
140145
upper := nibbles >> 4
141146
lower := nibbles & 0xf

src/machine/machine_atsamd51.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ var pinPadMapping = [64]uint16{
322322
// (indicated by returning ok=false). The pad number is returned to calculate
323323
// the DOPO/DIPO bitfields of the various serial peripherals.
324324
func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok bool) {
325+
if int(pin)/2 >= len(pinPadMapping) {
326+
// This is probably NoPin, for which no mapping is available.
327+
return
328+
}
329+
325330
bytes := pinPadMapping[pin/2]
326331
upper := byte(bytes >> 8)
327332
lower := byte(bytes & 0xff)

0 commit comments

Comments
 (0)