arduino / arduino/ArduinoCore-sam
bitWrite macro incorrectly expands ternary operator
- Dominant language
- HTML
- Stars
- 91
- Forks
- 112
- PR merge metrics
- No merged PRs in 30d
Description
_From @svatoun on December 13, 2016 8:34_
let's have a bitWrite(data, bitIndex, computedValue == 5 ? 1: 0);
bitWrite macro definition lacks parenthesis around the `bitvalue' parameter, so it expands as follows
(computedValue == 5 ? 1 : 0 ? bitSet(value, bit) : bitClear(value, bit))
and the `0 ? bitSet...' is then compiled as the false branch of the ternary operator in the passed expression.
Please correct the definition as follows:
#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))
(parenthesis added)
_Copied from original issue: arduino/Arduino#5714_
Contributor guide
No contributing guide indexed for this repository
Research direction
Locate the bitWrite macro definition in ArduinoCore-sam and inspect how the bitvalue parameter is expanded in a ternary call. Confirm that parenthesizing that parameter prevents the passed expression from changing the macro's conditional grouping, then validate the affected compilation case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100