CWE-484

Omitted Break Statement in Switch. [Behavioral-Problems, Improper-Adherence-To-Coding-Standards]

Required inputs: IR

The product omits a break statement within a switch or similar construct, causing code associated with multiple conditions to execute. This can cause problems when the programmer only intended to execute code associated with one condition. This can lead to critical code executing in situations where it should not.
Demonstrative Examples
Example 1

In both of these examples, a message is printed based on the month passed into the function:

Example Language:Java (Unsupported language for documentation only)
    public void printMessage(int month){
        switch (month) {
            case 1: print("January");
            case 2: print("February");
            case 3: print("March");
            case 4: print("April");
            case 5: print("May");
            case 6: print("June");
            case 7: print("July");
            case 8: print("August");
            case 9: print("September");
            case 10: print("October");
            case 11: print("November");
            case 12: print("December");
        }
        println(" is a great month");
    }
Example Language:C
    void printMessage(int month){
        switch (month) {
            case 1: printf("January");
            case 2: printf("February");
            case 3: printf("March");
            case 4: printf("April");
            case 5: printf("May");
            case 6: printf("June");
            case 7: printf("July");
            case 8: printf("August");
            case 9: printf("September");
            case 10: printf("October");
            case 11: printf("November");
            case 12: printf("December");
        }
        printf(" is a great month");
    }

Both examples do not use a break statement after each case, which leads to unintended fall-through behavior. For example, calling "printMessage(10)" will result in the text "OctoberNovemberDecember is a great month" being printed.

Excerpts from CWE [https://cwe.mitre.org], Copyright (C) 2006-2026, the MITRE Corporation. See section 9.4. "3rd-Party Licenses" in the documentation for full details.

Possible Messages

Key

Text

Severity

Disabled

unterminated_case

This switch-case is not {}, last statement is {}.

None

False

unterminated_empty_case

This switch-case is empty, not {}.

None

False

Options

acceptable_end_items

acceptable_end_items : set[bauhaus.ir.PIR_Class_Name] = {'Exit_Switch'}

Allowed last items at the end of a switch.
 

acceptable_middle_items

acceptable_middle_items : set[bauhaus.ir.PIR_Class_Name] = {'Exit_Switch', 'Nondefault_Case_Label'}

Allowed last items in the middle of a switch.
 

allow_empty_statements

allow_empty_statements : bool = False

Whether empty statements at the end of switch-case should be ignored.
 

allow_fallthrough_comment

allow_fallthrough_comment : bool = True

Allow comments with text including both "fall" and "through" simultaneously.
 

allow_fallthrough_macro

allow_fallthrough_macro : bool = True

Allows the __fallthrough macro as marker for allowed fallthrough.
 

allow_if

allow_if : bool = False

Whether an if containing acceptable items at the end of both branches is accepted.
 

allow_noreturn_function_calls

allow_noreturn_function_calls : bool = False

Whether a function call to a [[noreturn]] function is considered a valid termination.
 

allow_switch

allow_switch : bool = False

Whether a switch containing acceptable items at the end of all cases is accepted.
 

comment

comment : set[str] = set()

The comment that indicates an intentional fallthrough. Can be a set of strings.