/* >>>------------------------------------------------------------ * * File: rule_13.2.c, Module: M2CM-3.2-QAC-8.1.2 * * RULE 13.2 (Advisory): * Tests of a value against zero should be made explicit, unless * the operand is effectively Boolean. * * Implemented by messages: * 3344 Controlling expression is not an 'essentially Boolean' * expression. * * 4528 An expression of 'essentially enum' type (%1s) is being * used as the %2s operand of this logical operator (%3s). * * 4529 An expression of 'essentially enum' type (%1s) is being * used as the first operand of this conditional operator * (%2s). * * 4538 An expression of 'essentially signed' type (%1s) is * being used as the %2s operand of this logical operator * (%3s). * * 4539 An expression of 'essentially signed' type (%1s) is * being used as the first operand of this conditional * operator (%2s). * * 4548 A non-negative constant expression of 'essentially * signed' type (%1s) is being used as the %2s operand of * this logical operator (%3s). * * 4549 A non-negative constant expression of 'essentially * signed' type (%1s) is being used as the first operand of * this conditional operator (%2s). * * 4558 An expression of 'essentially unsigned' type (%1s) is * being used as the %2s operand of this logical operator * (%3s). * * 4559 An expression of 'essentially unsigned' type (%1s) is * being used as the first operand of this conditional * operator (%2s). * * 4568 An expression of 'essentially floating' type (%1s) is * being used as the %2s operand of this logical operator * (%3s). * * 4569 An expression of 'essentially floating' type (%1s) is * being used as the first operand of this conditional * operator (%2s). * * <<<------------------------------------------------------------ */ /* PRQA S 2961,2981,2982,2983,3112,3399 ++ */ #include "misra.h" #include "m2cmex.h" enum E {ONE, TWO}; extern S16 test_1302( void ) { if ( s16a ) /* MISRA Violation */ { s16r= 1; } s16c = s16a ? s16a : s16b; /* MISRA Violation */ if ( s16a + s16b ) /* MISRA Violation */ { s16r= 2; } if ( s16a != 0 ) /* OK */ { s16r= 3; } if ( s16a > s16b ) /* OK */ { s16r= 4; } if ( s16a = s16b ) /* MISRA Violation - also Rule 13.1 */ { s16r= 5; } { enum E a; (a && TWO); /* MISRA Violation */ (TWO || !a); /* MISRA Violation */ } { enum E a; (a ? 0 : 1); /* MISRA Violation */ } { (s16a && bla); /* MISRA Violation */ (s16a || !s16a); /* MISRA Violation */ } { (1 && bla); /* MISRA Violation */ (bla || !1); /* MISRA Violation */ } { (1 ? 0 : 1); /* MISRA Violation */ } { (u16a && bla); /* MISRA Violation */ (u16a || !u16a); /* MISRA Violation */ } { (u16a ? 0 : 1); /* MISRA Violation */ } { (f32a && bla); /* MISRA Violation */ (f32a || !f32a); /* MISRA Violation */ } { (f32a ? 0 : 1); /* MISRA Violation */ } return s16r; }