Skip to main content

IAR Embedded Workbench for RISC-V 3.40

CERT-EXP46-C

In this section:
Synopsis

Do not use a bitwise operator with a Boolean-like operand.

Enabled by default

Yes

Severity/Certainty

Low/High

lowhigh.png
Full description

Mixing bitwise and relational operators in the same full expression can be a sign of a logic error in the expression where a logical operator is usually the intended operator. Do not use the bitwise AND (&), bitwise OR (|), or bitwise XOR (^) operators with an operand of type _Bool, or the result of a relational-expression or equality-expression.

Coding standards
CERT EXP46-C

Do not use a bitwise operator with a Boolean-like operand

CWE 480

Use of Incorrect Operator

Code examples

The following code example fails the check and will give a warning:

unsigned int getuid();
unsigned int geteuid();
void example(void) {
    if (!(getuid() & geteuid() == 0)) {
        /* ... */
    }
}

The following code example passes the check and will not give a warning about this issue:

unsigned int getuid();
unsigned int geteuid();
void example(void) {
    if (!(getuid() && geteuid() == 0)) {
        /* ... */
    }
}