From ea1e0e95636dc1d78b80ee98bc85452459895667 Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Tue, 15 Jun 2021 12:32:40 -1000 Subject: [PATCH] Better - but not perfect - pin number error checking --- Grbl_Esp32/src/Pins/GPIOPinDetail.cpp | 3 ++- Grbl_Esp32/src/Pins/I2SOPinDetail.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Grbl_Esp32/src/Pins/GPIOPinDetail.cpp b/Grbl_Esp32/src/Pins/GPIOPinDetail.cpp index 9cebe6c9..ecf29c44 100644 --- a/Grbl_Esp32/src/Pins/GPIOPinDetail.cpp +++ b/Grbl_Esp32/src/Pins/GPIOPinDetail.cpp @@ -104,7 +104,8 @@ namespace Pins { // that were allocated by the constructor up to that point _MUST_ be freed! Otherwise, you // WILL get into trouble. - Assert(_capabilities != PinCapabilities::None, "Bad GPIO number"); + Assert(index < nGPIOPins, "Pin number is greater than max %d", nGPIOPins - 1); + Assert(_capabilities != PinCapabilities::None, "Unavailable GPIO"); Assert(!_claimed[index], "Pin is already used."); // User defined pin capabilities diff --git a/Grbl_Esp32/src/Pins/I2SOPinDetail.cpp b/Grbl_Esp32/src/Pins/I2SOPinDetail.cpp index 2433f40c..51cab9d1 100644 --- a/Grbl_Esp32/src/Pins/I2SOPinDetail.cpp +++ b/Grbl_Esp32/src/Pins/I2SOPinDetail.cpp @@ -30,6 +30,7 @@ namespace Pins { I2SOPinDetail::I2SOPinDetail(uint8_t index, const PinOptionsParser& options) : PinDetail(index), _capabilities(PinCapabilities::Output | PinCapabilities::I2S), _attributes(Pins::PinAttributes::Undefined), _readWriteMask(0) { + Assert(index < nI2SOPins, "Pin number is greater than max %d", nI2SOPins - 1); Assert(!_claimed[index], "Pin is already used."); // User defined pin capabilities for (auto opt : options) {