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

MISRA.STDLIB.LONGJMP

Use of setjmp macro or longjmp function.

MISRA C 2012 Rule 21.4: The standard header file <setjmp.h> shall not be used

C90 [Unspecified 14; Undefined 64–67]

C99 [Unspecified 32; Undefined 118–121, 173]

[Koenig 74]

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

None of the facilities that are specified as being provided by <setjmp.h> shall be used.

Rationale

setjmp and longjmp allow the normal function call mechanisms to be bypassed. Their use may lead to undefined and unspecified behaviour.

MISRA-C 2004 Rule 20.7 (required): The setjmp macro and the longjmp function shall not be used

Use of setjmp macro or longjmp function.

This rule is also covered by MISRA.EXPANSION.UNSAFE.

[Unspecified 14; Undefined 64—67, Koenig 74]

setjmp and longjmp allow the normal function call mechanisms to be bypassed, and shall not be used.

MISRA-C++ 2008 Rule 17-0-5 (required): The setjmp macro and the longjmp function shall not be used.

This rule is also covered by MISRA.EXPANSION.UNSAFE.

Rationale

setjmp and longjmp allow the normal function call mechanisms to be bypassed, and shall not be used, since exception handling provides a better defined mechanism for this.

Example

#include <setjmp.h>

void f2 ( );

jmp_buf buf;

void f1 ( )
{
   if ( !setjmp ( buf ) ) // Non-compliant
   {
      f2 ( );
   }
   else
   {
   }
}
void f2 ( )
{
   longjmp ( buf, 10 ); // Non-compliant
}