<div>I'm interested in trying out clang based code analysis. I saw the following slides:<br><a href="http://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf"><br class="">http://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf</a> <br clear="all">
<br class="">So thought I'd try using tools/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp as a base for a similar check using our products' internal file API.</div><div><br></div><div>In the sample, there's the following code to get the close parameter:<br>
<br>void SimpleStreamChecker::checkPreCall<br></div><div>...</div><div><div> // Get the symbolic value corresponding to the file handle.</div><div> SymbolRef FileDesc = Call.getArgSVal(0).getAsSymbol();</div></div><div>
<br></div><div>I'll want to do the same thing, with a small difference. My close API looks like:<br><br>struct my_filehandle { int fh ; ... } ;<br><br>int myclose( my_filehandle & fh )</div><div><br>so once I get the close parameter symbol, I have the task of looking up the actual file descriptor.<br>
<br>I'm guessing that I have to:<br><br>1) check it for -1 instead of NULL (hardcoding the assumption for now that I'm only running this checking on Unix)</div><div><br>I've changed:<br><br>ConditionTruthVal OpenFailed = CMgr.isNull(State, Sym);<br>
<br>to call isNegative(), which I think will do the trick, provided I first:</div><div><br></div><div>2) find the symbol that the myclose() parameter is a reference to.<br>3) look up the my_filehandle::fh value out of that symbol.<br>
</div><div>4) put that ::fh symbol in the checker stream instead of the FILE*.</div><div><br></div><div>Anybody willing to give any tips on how to do 2-3 above.</div><div><br></div>-- <br>Peeter<br>