If control reaches the end of a non-void function, using the return value of the function call results in causes undefined behavior. See also undefined behavior 7 of Appendix J.
This rule is related to recommendation MSC01-C. Strive for logical completeness because both rules involve ensuring are intended to ensure that programs properly handle all possible conditions.
...
In this noncomplaint code example, control reaches the end of the the getlen()
function when input
does not contain the integer delim
. As Because the potentially undefined return value of getlen
is later used as an index into an array, this can lead to a buffer overflow.
...
When the following is compiled with -Wall
on most versions of the GCC compiler, the following warning is generated:
Code Block |
---|
example.c: In function âgetlenâ: example.c:12: warning: control reaches end of non-void function |
...