Skip to content

pinMode() does not check valid pin number #149

Open
@mikaelpatel

Description

@mikaelpatel

The current pinMode() implementation performs a digitalPinToPort(pin) and then checks the port for NOT_A_PORT but digitalPinToPort() is a program memory table read. It is possible to give an illegal pin number.

Possible correction is:

void pinMode(uint8_t pin, uint8_t mode)
{
    if (pin >= NUM_DIGITAL_PINS) return;
    uint8_t bit = digitalPinToBitMask(pin);
    uint8_t port = digitalPinToPort(pin);
    volatile uint8_t *reg, *out;
    ...
}

Replacing the port check with a pin number check (first).

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions