If control reaches the closing curly brace (}) of a non-void function without evaluating a return statement, using the return value of the function call is undefined behavior. (See undefined behavior 8886.)
Noncompliant Code Example
...
Using the return value from a non-void function where control reaches the end of the function without evaluating a return statement can lead to buffer overflow vulnerabilities as well as other unexpected program behaviors.
Rule | Severity | Likelihood | Detectable | Remediation CostRepairable | Priority | Level |
|---|---|---|---|---|---|---|
MSC37-C | High | Unlikely | Yes | NoLow | P9P6 | L2 |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...
| Tool | Version | Checker | Description | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Astrée |
| return-implicit | Fully checked | |||||||
| Axivion Bauhaus Suite |
| CertC-MSC37 | ||||||||
| CodeSonar |
| LANG.STRUCT.MRS | Missing return statement | |||||||
| Coverity |
| MISSING_RETURN | Implemented | |||||||
| Cppcheck |
| missingReturn | Fully implemented | |||||||
| Cppcheck Premium |
| missingReturnFully implemented | ||||||||
| Helix QAC |
| C++4022 DF2888 | ||||||||
| Klocwork |
| FUNCRET.GEN FUNCRET.IMPLICIT | ||||||||
| LDRA tool suite |
| 2 D, 36 S, 66 S | Fully implemented | |||||||
| Parasoft C/C++test |
| CERT_C-MSC37-a | All exit paths from a function, except main(), with non-void return type shall have an explicit return statement with an expression | |||||||
| PC-lint Plus |
| 533 | Fully supported | |||||||
| Polyspace Bug Finder |
| CERT C: Rule MSC37-C | Checks for missing return statement (rule fully covered) | |||||||
| RuleChecker |
| return-implicit | Fully checked | |||||||
| Security Reviewer - Static Reviewer |
| RTOS_09 | Fully implemented | |||||||
| SonarQube C/C++ Plugin |
| S935 | ||||||||
| TrustInSoft Analyzer |
| Body of function falls-through | Exhaustively verified. |
...