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

UNUSED.FUNC.GEN

Unused function

Function defined but not used.

Vulnerability and risk

A defined but unused function can have few implications. It can lead to development confusion such as the wrong function having similar name being called. In some rare occasions the unused function may also find its way to the final executable which may lead to other vulnerabilities. This checker is mostly concerned about static functions that are not used. By definition static functions cannot be called from outside of the translation unit (unless they are inside a header file and included in multiple translation units).

Vulnerable code example 1

1  static void used() {}
2  static void unused() {}
3  int main() {
4    used();
5    return 0;
6  }

In the above code snippet the function "unused()" is defined as static but never used within the current translation unit; hence should be removed. Klocwork produces UNUSED.FUNC.GEN on line 2 alerting the developer.

Fixed code example 1

1  static void used() {}
2  int main() {
3    used();
4    return 0;
5  }

In order to fix the issue the function “unused()” is simply removed from the file.

Vulnerable code example 2

1  static void foo(int x) {}
2  static void foo(int x, int y) {}
3  int main() {
4    foo(0,0);
5    return 0;
6  }

Similar idea but in the context of overloaded functions. Klocwork produces UNUSED.FUNC.GEN on line 1.

Fixed code example 2

1  static void used(int x, int y) {}
2  int main() {
3    used(0,0);
4    return 0;
5  }

The unused version of foo – "foo(int)" is simply removed.

Related checkers