Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this noncompliant code example, a bitwise & operator operator is used with the results of an two equality-expressionexpressions:

Code Block
bgColor#FFcccc
langc
if (!(getuid() == 0 & geteuidgetgid() == 0)) { 
  /* ... */ 
} 

Compliant Solution

...

Code Block
bgColor#ccccff
langc
if (!(getuid() == 0 && geteuidgetgid() == 0)) {
  /* ... */
}

Risk Assessment

...

a
CERT_C-EXP46-The operands of logical operators (&&, || and !) should be effectively Boolean
PRQA QA-C

Tool

Version

Checker

Description

Astrée
Include Page
Astrée_V
Astrée_V
inappropriate-boolSupported indirectly via MISRA C:2012 Rule 10.1
Axivion Bauhaus Suite

Include Page
Axivion Bauhaus Suite_V
Axivion Bauhaus Suite_V

CertC-EXP46
CodeSonar
Include Page
CodeSonar_V
CodeSonar_V
LANG.TYPE.IOTInappropriate operand type

Coverity

Include Page
Coverity_V
Coverity_V

CONSTANT_EXPRESSION_RESULT

Partially implemented

Cppcheck
Include Page
Cppcheck_V
Cppcheck_V
cert.py
_V
bitwiseOnBoolean
Cppcheck Premium

Include Page
Cppcheck Premium_V
Cppcheck Premium_V

bitwiseOnBoolean
Helix QAC

Include Page
Helix QAC_V
Helix QAC_V

C3344, C4502

C++3709

Detected by the addon cert.py


Klocwork
Include Page
Klocwork_V
Klocwork_V
MISRA.LOGIC.OPERATOR.NOT_BOOL
LDRA tool suite
Include Page
LDRA_V
LDRA_V
136 SFully Implemented
Parasoft C/C++test
Include Page
Parasoft_V
Parasoft_V

CERT_C-EXP46-

b

Expressions that are effectively Boolean should not be used as operands to operators other than (&&, ||, !, =, ==, !=, ?:)

PC-lint Plus

Include Page
PC-lint Plus_V
PC-lint Plus_V

514

Fully supported

Polyspace Bug Finder

Include Page
Polyspace Bug Finder_V
Polyspace Bug Finder_V

CERT C: Rule EXP46-C

Checks for bitwise operations on boolean operands (rule fully covered)

Include Page
PRQA QA-C_vPRQA QA-C_v3344,4502PRQA CA-C++
Include Page
cplusplus:PRQA QA-C++_Vcplusplus:PRQA QA-C++_V
3709PVS-Studio

Include Page
PVS-Studio_V
PVS-Studio_V

V564, V1015

RuleChecker

Include Page
RuleChecker_V
RuleChecker_V

inappropriate-boolSupported indirectly via MISRA C:2012 Rule 10.1
Security Reviewer - Static Reviewer

Include Page
Security Reviewer - Static Reviewer_V
Security Reviewer - Static Reviewer_V

C73Fully implemented

Related Guidelines

Key here (explains table format and definitions)

...