Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 0-1-6 and Boolean variables
#3
Unfortunately the function bodies are not switched.
Code:
bool non_compliant_and (void)
{
    bool const b1 = random_bool();  // Assume this value is false.
    bool const b2 = random_bool();  // This can be any value.

   /*  Due to short-circuit evaluation, the value of b2 is never evaluated (read).
    *  This causes a DU dataflow anomaly for b2, and hence the MISRA C++ Rule 0-1-6 violation.
    */
    return b1 && b2;  
}

The short-circuit evaluation is a required part of the language: C++ reference on logical operators
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)