Fix overflow risk in strobeBlinkPin by updating parameter types and loop counter #519
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a potential overflow issue in the
strobeBlinkPin
function in the Firmata library by changing the types of the parameters and the loop counter to unsigned integer types.Changes made
count
parameter fromint
tounsigned int
to reflect that it cannot be negative.onInterval
andoffInterval
fromint
touint32_t
to support longer delay durations and prevent negative values.byte
tounsigned int
for correct loop iteration whencount
is greater than 255..cpp
and.h
files for consistency.Why this is important
Previously, using a
byte
for the loop counter could cause overflow and incorrect behavior whencount
exceeds 255, potentially leading to infinite loops or premature termination. Similarly, using signed integers for timing parameters could allow negative values, causing unexpected delays.This fix ensures type safety, correct loop behavior, and better support for longer timing intervals.
Additional notes
Please review and let me know if you'd like to discuss or improve the approach further.