Skip to content

bitWrite macro does not enclose argument in () #4466

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

Closed
positron96 opened this issue Oct 31, 2020 · 3 comments · Fixed by #4507
Closed

bitWrite macro does not enclose argument in () #4466

positron96 opened this issue Oct 31, 2020 · 3 comments · Fixed by #4507

Comments

@positron96
Copy link
Contributor

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

@lbernstone
Copy link
Contributor

Please submit a PR. You can do so right on that page by clicking the edit (pencil) icon.

@positron96
Copy link
Contributor Author

Huh, didn't know it was that easy.

@lbernstone
Copy link
Contributor

Well, you got the fork part done. It should have had some option in there to create the pull request. If you go to the main repo page now, you should see a message at the very top showing that you have an edit ready for a pull request. Click on that button and it should take you to the PR page. Enter fixes #4466 in the comment box and create the pull request.

@positron96 positron96 mentioned this issue Nov 8, 2020
me-no-dev pushed a commit that referenced this issue Nov 9, 2020
fpistm pushed a commit to stm32duino/Arduino_Core_STM32 that referenced this issue Aug 24, 2021
Current version does not wrap arguments in "()", so works incorrectly when used like this:
```
bitWrite(var, bit, cond?1:0);
```


Same as in here: espressif/arduino-esp32#4466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants