1// Check violations for rule 14.4 2// https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_14_04.c 3// 4// Confidence: Moderate 5// Copyright: (C) 2021 Intel Corporation 6// 7// SPDX-License-Identifier: Apache-2.0 8 9virtual report 10 11 12@initialize:python@ 13@@ 14 15@rule1_base@ 16identifier function, v; 17type T1, T2; 18parameter list[n] P1; 19parameter list[n1] P2; 20@@ 21( 22T1 function(P1, T2 v, P2) {...} 23| 24T1 function(P1, T2 *v, P2) {...} 25) 26 27@ script:python @ 28t << rule1_base.T2; 29v << rule1_base.v; 30@@ 31 32if t == "bool": 33 cocci.include_match(False) 34 35@rule1@ 36identifier rule1_base.v; 37position p; 38@@ 39( 40while (v@p) {...} 41| 42if (v@p) {...} 43) 44 45@ script:python @ 46p << rule1.p; 47@@ 48 49msg = "WARNING: Violation to rule 14.4 (Controlling expression shall have essentially Boolean type)" 50coccilib.report.print_report(p[0], msg) 51 52@rule2_base@ 53identifier v; 54type T; 55@@ 56T v; 57... 58 59@ script:python @ 60t << rule2_base.T; 61v << rule2_base.v; 62@@ 63 64if t == "bool": 65 cocci.include_match(False) 66 67 68@rule2@ 69position p; 70identifier rule2_base.v; 71@@ 72while (v@p) {...} 73 74@ script:python @ 75p << rule2.p; 76@@ 77 78msg = "WARNING: Violation to rule 14.4 (Controlling expression shall have essentially Boolean type)" 79coccilib.report.print_report(p[0], msg) 80 81@rule3@ 82position p; 83constant c; 84@@ 85( 86while (c@p) {...} 87| 88while (!c@p) {...} 89| 90if (c@p) {...} 91| 92if (!c@p) {...} 93) 94 95@ script:python @ 96p << rule3.p; 97@@ 98 99msg = "WARNING: Violation to rule 14.4 (Controlling expression shall have essentially Boolean type)" 100coccilib.report.print_report(p[0], msg) 101