mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-23 13:59:02 +00:00
atsam: add a length check to findPinPadMapping
This commit is contained in:
@@ -136,6 +136,11 @@ var pinPadMapping = [32]byte{
|
|||||||
// found" (indicated by returning ok=false). The pad number is returned to
|
// found" (indicated by returning ok=false). The pad number is returned to
|
||||||
// calculate the DOPO/DIPO bitfields of the various serial peripherals.
|
// calculate the DOPO/DIPO bitfields of the various serial peripherals.
|
||||||
func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok bool) {
|
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]
|
nibbles := pinPadMapping[pin/2]
|
||||||
upper := nibbles >> 4
|
upper := nibbles >> 4
|
||||||
lower := nibbles & 0xf
|
lower := nibbles & 0xf
|
||||||
|
|||||||
@@ -322,6 +322,11 @@ var pinPadMapping = [64]uint16{
|
|||||||
// (indicated by returning ok=false). The pad number is returned to calculate
|
// (indicated by returning ok=false). The pad number is returned to calculate
|
||||||
// the DOPO/DIPO bitfields of the various serial peripherals.
|
// the DOPO/DIPO bitfields of the various serial peripherals.
|
||||||
func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok bool) {
|
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]
|
bytes := pinPadMapping[pin/2]
|
||||||
upper := byte(bytes >> 8)
|
upper := byte(bytes >> 8)
|
||||||
lower := byte(bytes & 0xff)
|
lower := byte(bytes & 0xff)
|
||||||
|
|||||||
Reference in New Issue
Block a user