/* >>>------------------------------------------------------------ * * File: rule_21.1.c, Module: M2CM-3.2-QAC-8.1.2 * * RULE 21.1 (Required): * Minimisation of run-time failures shall be ensured by the use * of at least one of (a) static analysis tools/techniques; (b) * dynamic analysis tools/techniques; (c) explicit coding of checks * to handle run-time faults * * Implemented by messages: * 2791 Definite: Right hand operand of shift operator is * negative or too large. * * 2792 Apparent: Right hand operand of shift operator is * negative or too large. * * 2801 Definite: Overflow in signed arithmetic operation. * * 2802 Apparent: Overflow in signed arithmetic operation. * * 2811 Definite: Dereference of NULL pointer. * * 2812 Apparent: Dereference of NULL pointer. * * 2821 Definite: Arithmetic operation on NULL pointer. * * 2822 Apparent: Arithmetic operation on NULL pointer. * * 2831 Definite: Division by zero. * * 2832 Apparent: Division by zero. * * 2841 Definite: Dereference of an invalid pointer value. * * 2842 Apparent: Dereference of an invalid pointer value. * * 2845 Constant: Maximum number of characters to be written is * larger than the target buffer size. * * 2846 Definite: Maximum number of characters to be written is * larger than the target buffer size. * * 2847 Apparent: Maximum number of characters to be written is * larger than the target buffer size. * * 2871 Infinite loop identified. * * 2872 This loop, if entered, will never terminate. * * 2877 This loop will never be executed more than once. * * 2891 Definite: Negative value implicitly converted to an * unsigned type. * * 2892 Apparent: Negative value implicitly converted to an * unsigned type. * * 2896 Definite: Negative value cast to an unsigned type. * * 2897 Apparent: Negative value cast to an unsigned type. * * 2901 Definite: Positive integer value truncated by implicit * conversion to a smaller unsigned type. * * 2902 Apparent: Positive integer value truncated by implicit * conversion to a smaller unsigned type. * * 2911 Definite: Wraparound in unsigned arithmetic operation. * * 2912 Apparent: Wraparound in unsigned arithmetic operation. * * 2980 The value of this function parameter is never used * before being modified. * * 2981 This initialization is redundant. The value of this * object is never used before being modified. * * 2982 This assignment is redundant. The value of this object * is never used before being modified. * * 2983 This assignment is redundant. The value of this object * is never subsequently used. * * 2984 This operation is redundant. The value of the result is * always '%1s'. * * 2985 This operation is redundant. The value of the result is * always that of the left-hand operand. * * 2986 This operation is redundant. The value of the result is * always that of the right-hand operand. * * <<<------------------------------------------------------------ */ /* PRQA S 2982,3203,3112 ++ */ #include "misra.h" #include "m2cmex.h" #include extern S16 test_2101( void ) { S16 ia[10]; if (s16a >= 30767) { s16r = s16a + 3000; /* MISRA Violation */ } s16r = s16a + 4000; /* MISRA Violation */ if (s16a < 0) { u16r = (U16)s16a; /* MISRA Violation */ } u16r = (U16)s16a; /* MISRA Violation */ if (s16c == 0) { s16r = s16r / s16c; /* MISRA Violation */ } s16r = s16r / s16c; /* MISRA Violation */ if (u16a >= 0x1FFFU) { u16r = u16a * 16U; /* MISRA Violation */ } u16r = 10U - u16a; /* MISRA Violation */ if (s16b > 9) { ia [s16b] = 1; /* MISRA Violation */ } ia[s16b] = 1; /* MISRA Violation */ { PC a[10]; PC b[11]; strncpy(a, b, sizeof(b)); /* MISRA Violation */ } { PC a[10]; PC b[11]; if (s16a > sizeof(a)) { strncpy(a, b, s16a); /* MISRA Violation */ } } { PC a[10]; PC b[11]; if (s16a > sizeof(a)) { } strncpy(a, b, s16a); /* MISRA Violation */ } { if (u16a < 10) { if (u16b >= 10) { u16c = u16a / u16b; /* MISRA Violation */ } } } { if (u16b > u16a) { u16a % u16b; /* MISRA Violation */ } u16a << 0; /* MISRA Violation */ u16b | 0; /* MISRA Violation */ } { 0 | u16a; /* MISRA Violation */ 0xFFFFFFFFu & u16a; /* MISRA Violation */ s16a = 1; s16a * u16a; /* MISRA Violation */ } { S16 i; for (i = 0; i < 1; ++i) /* MISRA Violation */ { } i = 10; while (i <= 10) /* MISRA Violation */ { ++i; } } return s16r; }