Rule Definition
setjmp and longjmp allow the normal function call mechanisms to be bypassed. Their use may lead to undefined and unspecified behavior.
Remediation
Use exception handling
Violation Code Sample
#include <setjmp.h>
void f2 ( );
jmp_buf buf;
void f1 ( )
{
if ( !setjmp ( buf ) ) // Non-compliant
{
f2 ( );
}
else
{
}
}
void f2 ( )
{
longjmp ( buf, 10 ); // Non-compliant
}
Reference
Standards Reference
MISRA C 2012 - 21.4: The standard header file shall not be used
MISRA C++ 2008 17-0-5: The setjmp macro and the longjmp function shall not be used.
Related Technologies
Technical Criterion
CWE-758 - Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.