<div dir="ltr">Hi,<div>I was running the following code through clang SA -</div><div><br></div><div><div>#include <stdlib.h></div><div>int* myAlloca(int i,int maxCount) {</div><div> if (i >= maxCount)</div><div> return 0;</div>
<div> int* k = (int*) malloc(sizeof(int));</div><div> return k;</div><div>}</div><div><br></div><div>int main() {</div><div> int max = 1;</div><div> for(int i =0;i< 2;i++) {</div><div> int* k = myAlloca(i,max);</div>
<div> *k = 1;</div><div> }</div><div> return 0;</div><div>}</div></div><div><br></div><div>This code will result in Null Deference in the second iteration of for loop. </div><div>When i debugged i found that the reason for it is by default null return paths are suppressed by clang SA.</div>
<div> </div><div>Running the above code with suppress-null-return-paths=false gives the desired result.</div><div><br></div><div>Any particular reason why this flag is enabled by default in clang SA? </div><div><br></div>
<div>Isn't it common in code to return null from a function in case we have a failure and hence can result in deref if used further? </div><div><br></div><div>Shouldn't we be disabling this by default? or am i missing something?</div>
<div><br></div><div>Thanks</div><div>Karthik Bhat</div><div><br></div><div><br></div><div><br></div></div>