...
Do not explicitly or implicitly call std::quick_exit()
, std::abort()
, or std::_Exit()
. When the default terminate_handler
is installed or the current terminate_handler
responds by calling std::abort()
or std::_Exit()
, do not explicitly or implicitly call std::terminate()
. Abnormal process termination is the typical vector for denial-of-service attacks.
The std::exit()
function is more complex. The C++ Standard, [basic.start.main], paragraph 4, states:
Terminating the program without leaving the current block (e.g., by calling the function std::exit(int) (17.5)) does not destroy any objects with automatic storage duration (11.4.6). If std::exit is called to end a program during the destruction of an object with static or thread storage duration, the program has undefined behavior.
You may call It is acceptable to call a termination function that safely executes destructors and properly cleans up resources, such as std::exit()
only in a program that has not yet initialized any objects with automatic storage duration.
Noncompliant Code Example
...
Tool | Version | Checker | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Astrée |
| stdlib-use | Partially checked | ||||||||||
CodeSonar |
| BADFUNC.ABORT | Use of abort | ||||||||||
Helix QAC |
| C++5014 | |||||||||||
Klocwork |
| MISRA.CATCH.ALLTERMINATE CERT.ERR.ABRUPT_TERM | |||||||||||
LDRA tool suite |
| 122 S | Enhanced Enforcement | ||||||||||
Parasoft C/C++test |
| CERT_CPP-ERR50-a | The execution of a function registered with 'std::atexit()' or 'std::at_quick_exit()' should not exit via an exception | ||||||||||
Polyspace Bug Finder |
| CERT C++: ERR50-CPP | Checks for implicit call to terminate() function (rule partially covered) | PRQA QA-C++||||||||||
PVS-Studio |
| PRQA QA-C++
| PRQA QA-C++_V |
| V667, V2014 | ||||||||
RuleChecker |
| stdlib-use | Partially checked | 5014||||||||||
SonarQube C/C++ Plugin |
| S990 |
...