Main Content

MISRA C:2012 Rule 21.8

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

Description

Rule Definition

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® flags the use of the abort, exit, _Exit, or quick_exit functions that are defined in <stdlib.h>.

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>

void foo(){
	 puts("pushed");
	//...
	_Exit(-1);//Noncompliant
}
void bar(){
	puts("pushed");
	//...
	abort();//Noncompliant
}
void foobar(){
	puts("pushed");
	//...
	quick_exit(-1);//Noncompliant
}

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

Version History

Introduced in R2014b