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

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

EXP46-C

Low

Likely

Low

P9

L2

Automated Detection

Tool

Version

Checker

Description

Astrée
Include Page
Astrée_V
Astrée_V
Supported, but no explicit checker
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.pyDetected by the addon cert.py
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


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
MISRA2004-12_6_a, MISRA2004-12_6_b

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

Fully implemented

Polyspace Bug Finder

Include Page
Polyspace Bug Finder_V
Polyspace Bug Finder_V

MISRA
CERT C:
2012 Rule 10.1

Operands shall not be of an inappropriate essential type

PRQA QA-C Include PagePRQA QA-C_vPRQA QA-C_v3344,4502
Rule EXP46-C

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

PVS-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
PRQA CA-C++4.2 3709PVS-Studio Include PagePVS-Studio_VPVS-Studio_VV564

Related Guidelines

Key here (explains table format and definitions)

...

Intersection( EXP45-C, EXP46-C) = Ø

CWE-480 = Union( EXP46-C, list) where list =

...