Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

INCONSISTENT.LABEL

Inconsistent case labels

The INCONSISTENT.LABEL checker finds situations in which more than one enum type is used as a switch expression or as a label in a switch statement.

Vulnerability and risk

Using labels with different enum types in a switch statement can cause problems because enum members with the same value can have different meanings. The design intent fails, and unexpected results can occur.

Vulnerable code example

1  typedef enum Q1{Q1Send, Q1Recv} Q1;
2  typedef enum Q2{Q2None, Q2Send, Q2Recv} Q2;
3  
4  // Inconsistency between switch variable and case labels
5  void foo1(Q1 q) {
6    switch (q) {
7      case Q2Send: f(); break;
8      case Q2Recv: g(); break;
9    }
10 }
11 
12 //Inconsistency between case labels
13 void foo2(Q1 q) {
14   switch (q) {
15     case Q1Send: f(); break;
16     case Q2Recv: g(); break;
17   }
18 }

Klocwork flags line 8 for foo1() to indicate that the type of variable used in the switch is different from the types of the case labels. Klocwork flags line 16 for foo2() to indicate that the case labels use enumerators from two different enum types.