-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Check for valid pin properly (fixes #4605) #4618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Current behavior: look up pin number in `digital_pin_to_port_PGM[]` and then check if it magically returned 0. Proposed behavior (from issue #4605): check if pin is within the valid range, and THEN look it up. Don't check afterwards. IMPORTANT NOTE: This change assumes that `digital_pin_to_port_PGM[]` doesn't skip any pin, which until now could have been done by assigning NOT_A_PIN to the position to skip. If it is planned to have boards where the pin numbering behaves like this, the `if (port == NOT_A_PIN) return;` part should be kept as well (assuming that `NUM_DIGITAL_PINS` will count the "holes" too).
Seems more than pinMode that had the same issue. Good job! |
@cousteaulecommandant thanks for submitting. Do you have an example of how this improves things from a user perspective? Some other notes:
|
I also think that this is not a good fix. And while the check @sandeepmistry mentioned still has to be there, this just adds more code, not less. |
Well, right now the check doesn't work at all; it doesn't provide any useful protection against invalid pins. So if code size is an issue I'd just remove both checks. And if I had to choose I'd prefer this check to the other. Also, I think that an alternative to having the second check (the one I removed) is that boards with "holes" leave a valid port in @NicoHood I'm not sure I understood, but if what you mean is that there might be boards where the highest pin is larger than Or just use |
Your suggestion still does not work. It does still not count holes. I guess the only real working check is the one we have right now. And I see no clue why the addition could help in any way, rather than breaking stuff. |
Rewrote this pull request as #4649 since it needed some editions but I had deleted the branch. |
Current behavior: look up pin number in
digital_pin_to_port_PGM[]
and then check if it magically returned 0.Proposed behavior (from issue #4605): check if pin is within the valid range, and THEN look it up. Don't check afterwards.
IMPORTANT NOTE: This change assumes that
digital_pin_to_port_PGM[]
doesn't skip any pin, which until now could have been done by assigning NOT_A_PIN to the position to skip. If it is planned to have boards where the pin numbering behaves like this, theif (port == NOT_A_PIN) return;
part should be kept as well (assuming thatNUM_DIGITAL_PINS
will count the "holes" too).