Skip to content

bitWrite macro does not enclose argument in () #4466

Closed
@positron96

Description

@positron96

Hello.

I've found a trivial bug in bitWrite macro. It's written as
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) and its argument bitvalue is not enclosed in parentheses. This gives incorrect result for some arguments, for example I've triggered the bug with this code:

bool b=true;
bitWrite(dst, bit, b?1:0);

The macro is here: https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/Arduino.h#L91 and it affects all versions of ESP32 core since it was introduced.

In AVR Arduino core this macro is correct:
https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/Arduino.h#L115

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