atsam: add a length check to findPinPadMapping

This commit is contained in:
sago35
2020-12-02 09:21:38 +09:00
committed by GitHub
parent 0c4f0b1ebf
commit 2540172cc5
2 changed files with 10 additions and 0 deletions
+5
View File
@@ -136,6 +136,11 @@ var pinPadMapping = [32]byte{
// found" (indicated by returning ok=false). The pad number is returned to
// calculate the DOPO/DIPO bitfields of the various serial peripherals.
func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok bool) {
if int(pin)/2 >= len(pinPadMapping) {
// This is probably NoPin, for which no mapping is available.
return
}
nibbles := pinPadMapping[pin/2]
upper := nibbles >> 4
lower := nibbles & 0xf
+5
View File
@@ -322,6 +322,11 @@ var pinPadMapping = [64]uint16{
// (indicated by returning ok=false). The pad number is returned to calculate
// the DOPO/DIPO bitfields of the various serial peripherals.
func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok bool) {
if int(pin)/2 >= len(pinPadMapping) {
// This is probably NoPin, for which no mapping is available.
return
}
bytes := pinPadMapping[pin/2]
upper := byte(bytes >> 8)
lower := byte(bytes & 0xff)