主要内容

MISRA C:2025 Rule 21.8

R2026b

The Standard Library termination functions of <stdlib.h> shall not be used

Since R2026b

Description

The Standard Library termination functions of <stdlib.h> shall not be used.

Rationale

Using these functions can cause undefined and implementation-defined behaviors.

Polyspace Implementation

Polyspace® reports a violation if your code contains any of the following:

  • Use of the abort, exit, _Exit, or quick_exit functions that are defined in <stdlib.h>.

  • Use of the macro assert while the preprocessor macro NDEBUG is not defined. The macro assert expands to call abort() when NDEBUG is undefined.

If these functions are user-defined, Polyspace does not flag them.

Troubleshooting

If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

#include<stdlib.h>
#undef NDEBUG
#include <assert.h>
void foo(){
	 puts("pushed");
	//...
	_Exit(-1);//Noncompliant
}
void bar(){
	puts("pushed");
	//...
	abort();//Noncompliant
}
void foobar(){
	puts("pushed");
	//...
	quick_exit(-1);//Noncompliant
}

int main( void )
{
    assert( 0 );    //Noncompliant- expands to call abort() */
}

//The use of the assert macro with NDEBUG defined expands to ((void)0), the null-statement:
#define NDEBUG
#include <assert.h>
int main2( void )
{
    assert( 0 );  // Rule does not apply - expands to void-expression 
}

In this example, unsafe termination functions are invoked to terminate the program. These functions might not perform the essential cleanup operations. For instance, the data pushed to the output stream might become lost because the program is terminated before the streams are closed. Polyspace flags the use of such unsafe termination programs.

Check Information

Group: Standard Libraries
Category: Required
AGC Category: Required
PQL Name: std.misra_c_2025.R21_8

Version History

Introduced in R2026b