Community
Participate
Working Groups
Build Identifier: I20100312-1448 In a function as follows CODAN does not report there is no expression for the return statement. int integer_return_function(void) { if (global) { if (global == 100) { return; // error here on line 4 } } } Reproducible: Always Steps to Reproduce: 1.Write a non void C function 2.Within the function write a return statement without expression. 3.See the Eclipse CDT problems window. Nothing is reported regarding the missing expression.
Created attachment 166710 [details] Proposal to check the returns expressions and report warning accordingly
I created a checker (sorry did not realize there is a patch, it is different code) I applied tests from patch though. It checks for 1) Return without a value for function EXPLICITLY defined with non-void return 2) Return with a value for function defined with void 3) No return at all for function EXPLICITLY defined with non-void return There are few issues now a) For #1 it may need a parameter to also return errors on function with implicit int (in this case exclude constructors) b) in case of #3 it has false positive if function does exit() or throw c) It has f.p. in #2 with ugly hack like this return (void)some();
Checked implemented. a) and b) from comment above are also corrected.
*** cdt cvs genie on behalf of elaskavaia *** Bug 311268 added checker to check for return values [*] plugin.xml 1.19 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/plugin.xml?root=Tools_Project&r1=1.18&r2=1.19 [+] ReturnChecker.java http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java?root=Tools_Project&revision=1.1&view=markup [+] AbstractAstFunctionChecker.java http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractAstFunctionChecker.java?root=Tools_Project&revision=1.1&view=markup [+] ExpressionRequiredInReturnCheckerTest.java http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ExpressionRequiredInReturnCheckerTest.java?root=Tools_Project&revision=1.1&view=markup [*] AutomatedIntegrationSuite.java 1.4 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/AutomatedIntegrationSuite.java?root=Tools_Project&r1=1.3&r2=1.4
*** cdt cvs genie on behalf of elaskavaia *** Bug 311268 fixed some f.p. in return checker [*] ControlFlowGraphBuilder.java 1.11 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/cfg/ControlFlowGraphBuilder.java?root=Tools_Project&r1=1.10&r2=1.11 [*] CxxModelsCache.java 1.3 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/CxxModelsCache.java?root=Tools_Project&r1=1.2&r2=1.3 [*] ControlFlowGraphTest.java 1.8 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cfg/ControlFlowGraphTest.java?root=Tools_Project&r1=1.7&r2=1.8 [*] ReturnChecker.java 1.2 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java?root=Tools_Project&r1=1.1&r2=1.2