Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Missing enum case in switch

ID: cpp/missing-case-in-switchKind: problemSecurity severity: Severity: warningPrecision: mediumTags:   - reliability   - correctness   - external/cwe/cwe-478Query suites:   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

This rule findsswitch statements that switch on values of an enumeration type but do not provide cases for all the enumeration constants or a default case. This is an indication that there may be cases unhandled by theswitch statement.

Recommendation

Provide a case for every enumeration constant, or introduce adefault case if several constants should be treated the same way.

Example

typedefenum{RED,ORANGE,YELLOW,GREEN,BLUE,INDIGO,VIOLET}colors;intf(colorsc){switch(c){caseRED://...caseGREEN://...caseBLUE://...//wrong: does not use all enum values, and has no default}switch(c){caseRED://...caseGREEN://...default://correct: does not use all enum values, but has a default}}

References


[8]ページ先頭

©2009-2025 Movatter.jp