From d9001b62a95e1d23f5cfa5cbda5dca7936c08bd5 Mon Sep 17 00:00:00 2001 From: Chris0xdeadbeef Date: Tue, 23 Sep 2025 15:45:37 +0200 Subject: [PATCH 1/2] fix(Firmata.cpp): use unsigned int and uint32_t in strobeBlinkPin to prevent overflow Changed the loop counter and interval parameters in strobeBlinkPin to use unsigned integer types (unsigned int for count and uint32_t for on/off intervals) to avoid overflow and incorrect behavior when count exceeds 255 or intervals are large. This fixes potential infinite loops or unexpected delays caused by using byte (uint8_t) types for variables that can hold larger values. --- Firmata.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Firmata.cpp b/Firmata.cpp index ee01f8f5..db3d1695 100644 --- a/Firmata.cpp +++ b/Firmata.cpp @@ -541,10 +541,9 @@ void FirmataClass::setPinState(byte pin, int state) * @param onInterval The number of milliseconds for the LED to be ON during each interval. * @param offInterval The number of milliseconds for the LED to be OFF during each interval. */ -void FirmataClass::strobeBlinkPin(byte pin, int count, int onInterval, int offInterval) +void FirmataClass::strobeBlinkPin(byte pin, unsigned int count, uint32_t onInterval, uint32_t offInterval) { - byte i; - for (i = 0; i < count; i++) { + for (unsigned int i = 0; i < count; ++i) { delay(offInterval); digitalWrite(pin, HIGH); delay(onInterval); From d324e29405a468e54022cc325406eee717b5df5b Mon Sep 17 00:00:00 2001 From: Chris0xdeadbeef Date: Tue, 23 Sep 2025 15:47:11 +0200 Subject: [PATCH 2/2] fix(Firmata.h): update strobeBlinkPin signature in header to use unsigned types Updated the strobeBlinkPin function prototype in the header file to use unsigned int for count and uint32_t for onInterval and offInterval to match the implementation and prevent overflow issues. This ensures type consistency and avoids potential bugs caused by signed or too-small integer types for timing and loop count parameters. --- Firmata.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmata.h b/Firmata.h index fb993d79..e4eeddf0 100644 --- a/Firmata.h +++ b/Firmata.h @@ -127,7 +127,7 @@ class FirmataClass boolean blinkVersionDisabled; /* private methods ------------------------------ */ - void strobeBlinkPin(byte pin, int count, int onInterval, int offInterval); + void strobeBlinkPin(byte pin, unsigned int count, uint32_t onInterval, uint32_t offInterval); friend void FirmataMarshaller::encodeByteStream (size_t bytec, uint8_t * bytev, size_t max_bytes) const; /* callback functions */