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

INFINITE_LOOP.MACRO

Infinite loop in macro

The INFINITE_LOOP checkers find instances of loops that have no exit. The checkers track the variables that control loop exit, flagging a defect if the conditions are invariant. When the validity of a condition doesn't change from one iteration to another, the loop never terminates.

The INFINITE_LOOP.MACRO checker finds infinite loops contained in macros. The typical use for the INFINITE_LOOP.MACRO checker is to separate the check for this type of infinite loop from those whose exit condition is based on a local variable. It is useful to be able to turn off the INFINITE_LOOP.MACRO checker when you want to check for significant infinite loops with INFINITE_LOOP.LOCAL.

Vulnerability and risk

An infinite loop can cause a program to hang up indefinitely or crash, possibly allowing a denial-of-service (DoS) attack due to excessive use of CPU or memory resources.

Vulnerable code example


1    #define HALT() do { } while (1)
2    void infinite_loop() {
3       HALT();
4    } 

Klocwork flags this example of an infinite loop, since the function will never exit. In this case, the loop is contained in the macro HALT, which has been placed in the code to cause a halt. This is an example of a situation that you typically wouldn't want to flag when searching for infinite loops, and INFINITE_LOOP.MACRO lets you separate it from the type of code defect you do want flagged.