CS.STMT.IFELSE.BLOCK
Body for If/Else statement should be a block.
The body of an if / else statement must be a block between {and}.
Vulnerability and risk
If you omit the curly braces if in the body of the if / else statement, a careless programming error may occur.
Mitigation and prevention
Use curly braces in the body of an if / else statement.
Vulnerable code example
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace kmcustom 8 { 9 class C18 10 { 11 public void doSomething() 12 { 13 14 } 15 16 public void testNGIf(int some_number) 17 { 18 19 if (some_number == 1) 20 doSomething(); 21 else if (some_number == 2) 22 doSomething(); 23 else 24 doSomething(); 25 26 27 if (some_number == 3) ; 28 else if (some_number == 4) ; 29 else; 30 31 } 32 33 public void testOKIf(int some_number) 34 { 35 36 if (some_number == 1) 37 { 38 doSomething(); 39 } 40 else if (some_number == 2) 41 { 42 doSomething(); 43 } 44 else { 45 doSomething(); 46 } 47 } 48 } 49 }