<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Yes; unfortunately the analyzer only processes one translation unit at a time (main source file + all included headers), just like the compiler. Support for cross-translation unit analysis is <i>way</i> down the line, since it's a huge restructuring of how we do things.</div><div><br></div><div>I think the only thing that's more standard about an enum is that it allows you to do fully-covered switch checks, if that's ever useful. It also means you can't take the address of the constants, which usually isn't important. One thing that the constants do allow is that if you ever depend on the value, you could change the value in the .c file without recompiling everything else. But you probably don't care about the value, other than possibly being non-positive.</div><div><br></div><div>Best,</div><div>Jordan</div><div><br></div><br><div><div>On Aug 7, 2013, at 1:34 , 凌欢 <<a href="mailto:linghuan713@126.com">linghuan713@126.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="line-height: 1.7; font-size: 14px; font-family: arial; "><div>hi, Jordan:<br>Our  Jce_c.h
file has the following define:</div><div><!--StartFragment --><div>
<em>extern const Int32 <strong>JCE_SUCCESS</strong>        ;      //成功</em><br>
<em>extern const Int32 JCE_ATTR_NOT_FOUND ;      //查找不到相关属性<br>extern const Int32 JCE_ENCODE_ERROR   ;      //编码错误<br>extern const Int32 JCE_DECODE_ERROR   ;      //解码错误<br>extern const Int32 JCE_RUNTIME_ERROR  ;      //其他运行时错误<br>extern const Int32 <strong>JCE_MALLOC_ERROR   </strong>;      //内存申请失败错误</em></div><em></em></div><div>While the Jce_c.c file has the following define:</div><div><!--StartFragment --><div>
<em>const Int32 <strong>JCE_SUCCESS</strong>        =  0;   //成功<br>const Int32 JCE_ATTR_NOT_FOUND = -1;    //查找不到相关属性<br>const Int32 JCE_ENCODE_ERROR   = -2;        //编码错误<br>const Int32 JCE_DECODE_ERROR   = -3;    //解码错误<br>const Int32 JCE_RUNTIME_ERROR  = -4;         //其他运行时错误<br>const Int32 <strong>JCE_MALLOC_ERROR</strong>   = -5;      //内存申请失败错误</em>
</div></div><div>So why the scan-build can't read the value from .c file ? Is it the weak point for the Clang?</div><div>In theory , put the the constants in an enum is more proper/stander codeing  ?</div><div>Thanks Jordan.</div><div> </div><div> BRs</div><div>
<div>Howard Ling </div>
<div>*****************************************************</div>
<div> </div>
<div>E-mail:    <a href="mailto:linghuan713@126.com">linghuan713@126.com</a></div>
<div> </div>
<div>*****************************************************</div></div><div id="divNeteaseMailCard"></div><div></div>At 2013-08-06 23:32:11,"Jordan Rose" <<a href="mailto:jordan_rose@apple.com">jordan_rose@apple.com</a>> wrote:<br> <blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" id="isReplyContent"><div>Right, then. You've never actually told the analyzer that JCE_SUCCESS and JCE_MALLOC_ERROR are distinct constants, so it's not going to be able to do a good job here. You can either make the definitions of the constants visible, or put them in an enum (same basic idea). (In theory you could assert that they are different, but the analyzer doesn't track relationships between independent symbolic values. Besides, you'd have to assert that in every function.)</div><div><br></div><div>Sorry for the inconvenience,</div><div>Jordan</div><div><br></div><br><div><div>On Aug 6, 2013, at 2:25 , 凌欢 <<a href="mailto:linghuan713@126.com">linghuan713@126.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="line-height: 1.7; font-family: arial; font-size: 14px;"><div><br>It is defined extern const Int 32.<br><br> BRs</div><div>
<div>Howard Ling </div>
<div>*****************************************************</div>
<div> </div>
<div>E-mail:    <a href="mailto:linghuan713@126.com">linghuan713@126.com</a></div>
<div> </div>
<div>*****************************************************</div></div><div></div><div></div>在 2013-08-03 09:12:56,"Jordan Rose" <<a href="mailto:jordan_rose@apple.com">jordan_rose@apple.com</a>> 写道:<br> <blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" id="isReplyContent"><br><div><div>On Aug 2, 2013, at 4:08 , 凌欢 <<a href="mailto:linghuan713@126.com">linghuan713@126.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="line-height: 1.7; font-family: arial; font-size: 14px;"><div>HI, all :</div><div>Our developers says that if set NULL to the pointer ,it can be used after released , is it right ? Following the the code which is </div><div>reported by scan-build and the type is used after release , <strong>can anyone tell me how to fix the bug ?</strong></div><div><strong>Or is it the false positive ? </strong> please see the attathed .c file for the detail which is start line 896, end line 942.</div><div> Thanks all . </div></div></blockquote></div><br><div>The false positive comes from this line:</div><div><br></div><div><table style="width: 3446px; line-height: 1.2em; font-family: monospace, monospace; font-size: 13px; border-collapse: collapse;" class="code"><tbody><tr><td style="padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 3px; border-left-style: solid; white-space: pre;" class="line">    <span style="color: blue;" class="keyword">if</span>(JCE_SUCCESS != ret) { <span style="color: blue;" class="keyword">return</span> <span style="color: rgb(139, 0, 139); position: relative; background-color: rgb(255, 250, 205);" class="macro">NULL</span>; }</td></tr><tr></tr></tbody></table><br></div><div>For some reason, we think that ret == JCE_SUCCESS when the allocation fails, but the path clearly shows JCE_MALLOC_ERROR being returned.  So now the only question is, why does the analyzer think JCE_MALLOC_ERROR and JCE_SUCCESS can be the same thing? Are they defined as "extern Int32" instead of constants?</div><div><br></div><div>Jordan</div></blockquote></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span></blockquote></div><br></blockquote></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span></blockquote></div><br></body></html>