<html>
 <body>
  <div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
   <table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 solid;">
    <tr>
     <td>
      This is an automatically generated e-mail. To reply, visit:
      <a href="https://reviewboard.asterisk.org/r/1743/">https://reviewboard.asterisk.org/r/1743/</a>
     </td>
    </tr>
   </table>
   <br />








<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
 <p style="margin-top: 0;">On March 1st, 2012, 7:12 a.m., <b>wdoekes</b> wrote:</p>
 <blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
  



<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; border-collapse: collapse; margin: 2px padding: 2px;">
 <thead>
  <tr>
   <th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; font-size: 9pt; padding: 4px 8px; text-align: left;">
    <a href="https://reviewboard.asterisk.org/r/1743/diff/2/?file=25176#file25176line3158" style="color: black; font-weight: bold; text-decoration: underline;">trunk/channels/chan_unistim.c</a>
    <span style="font-weight: normal;">

     (Diff revision 2)

    </span>
   </th>
  </tr>
 </thead>

 <tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
  <tr>

   <td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">static void show_history(struct unistimsession *pte, char way)</pre></td>

  </tr>
 </tbody>



 
 




 <tbody>

  <tr>
    <th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2">3158</font></th>
    <td bgcolor="#fdfebc" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">count</span><span class="p">)</span></pre></td>
    <th bgcolor="#e9eaa8" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">3156</font></th>
    <td bgcolor="#fdfebc" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">count</span><span class="p">)</span><span class="hl"> </span><span class="p"><span class="hl">{</span></span></pre></td>
  </tr>

 </tbody>



 
 



 <tbody>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">3157</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                <span class="n">fclose</span><span class="p">(</span><span class="n">f</span><span class="p">);</span></pre></td>
  </tr>

 </tbody>





 
 

 <tbody>

  <tr>
    <th bgcolor="#f0f0f0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2">3159</font></th>
    <td bgcolor="#ffffff" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                <span class="k">return</span><span class="p">;</span></pre></td>
    <th bgcolor="#f0f0f0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">3158</font></th>
    <td bgcolor="#ffffff" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                <span class="k">return</span><span class="p">;</span></pre></td>
  </tr>

 </tbody>



 
 



 <tbody>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">3159</font></th>
    <td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span class="p">}</span></pre></td>
  </tr>

 </tbody>

</table>

  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Wrong: OpenHistory takes care of most of the fclose&#39;s.

(1) Change OpenHistory to set *f = NULL after fclose and here do an if(f){fclose(f);}

or

(2) Have OpenHistory fclose(*f) if count==0.

Logically, I&#39;d prefer the first. But the second will reduce the amount of extra if&#39;s you&#39;ll have to write. Better go with the last one.</pre>
 </blockquote>



 <p>On March 1st, 2012, 4:43 p.m., <b>junky</b> wrote:</p>
 <blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">i would tend to agree, but not cppcheck.
Do you see any trouble to have those fclose() in there?</pre>
 </blockquote>







</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Yes, I see trouble. Thou shall not fclose a FILE pointer twice. And in all cases of errors, OpenHistory already closes it. The only missing fclose is when there is no error, but count is 0.</pre>
<br />

<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
 <p style="margin-top: 0;">On March 1st, 2012, 7:12 a.m., <b>wdoekes</b> wrote:</p>
 <blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
  



<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; border-collapse: collapse; margin: 2px padding: 2px;">
 <thead>
  <tr>
   <th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; font-size: 9pt; padding: 4px 8px; text-align: left;">
    <a href="https://reviewboard.asterisk.org/r/1743/diff/2/?file=25182#file25182line603" style="color: black; font-weight: bold; text-decoration: underline;">trunk/funcs/func_env.c</a>
    <span style="font-weight: normal;">

     (Diff revision 2)

    </span>
   </th>
  </tr>
 </thead>

 <tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
  <tr>

   <td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">static int file_read(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)</pre></td>

  </tr>
 </tbody>



 
 




 <tbody>

  <tr>
    <th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2">603</font></th>
    <td bgcolor="#fdfebc" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                        <span class="k">for</span> <span class="p">(</span><span class="n">pos</span> <span class="o">=</span> <span class="n">end</span> <span class="o">&lt;</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">fbuf</span><span class="p">)</span> <span class="o">?</span> <span class="n">fbuf</span> <span class="o">+</span> <span class="n">end</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">:</span> <span class="n">fbuf</span> <span class="o">+</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">fbuf</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="n">pos</span> <span class="o">&gt;</span> <span class="n">fbuf</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="n">pos</span><span class="o">--</span><span class="p">)</span> <span class="p">{</span></pre></td>
    <th bgcolor="#e9eaa8" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">603</font></th>
    <td bgcolor="#fdfebc" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">                        <span class="k">for</span> <span class="p">(</span><span class="n">pos</span> <span class="o">=</span> <span class="p"><span class="hl">(</span></span><span class="n">end</span> <span class="o">&lt;</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">fbuf</span><span class="p"><span class="hl">)</span>)</span> <span class="o">?</span> <span class="n">fbuf</span> <span class="o">+</span> <span class="n">end</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">:</span> <span class="n">fbuf</span> <span class="o">+</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">fbuf</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="n">pos</span> <span class="o">&gt;</span> <span class="n">fbuf</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="n">pos</span><span class="o">--</span><span class="p">)</span> <span class="p">{</span></pre></td>
  </tr>

 </tbody>

</table>

  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">How about:

pos = (end &lt; sizeof(fbuf) ? fbuf + end - 1 : fbuf + sizeof(fbuf) - 1)</pre>
 </blockquote>



 <p>On March 1st, 2012, 9:34 a.m., <b>junky</b> wrote:</p>
 <blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">that will keep the cppcheck warning, since the operator precedence isnt there.</pre>
 </blockquote>







</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">So it thinks we don&#39;t know that ?: has lower precedence than &lt; . Odd, but ok. I can live with this one.</pre>
<br />

<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
 <p style="margin-top: 0;">On March 1st, 2012, 7:12 a.m., <b>wdoekes</b> wrote:</p>
 <blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
  



<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; border-collapse: collapse; margin: 2px padding: 2px;">
 <thead>
  <tr>
   <th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; font-size: 9pt; padding: 4px 8px; text-align: left;">
    <a href="https://reviewboard.asterisk.org/r/1743/diff/2/?file=25194#file25194line1104" style="color: black; font-weight: bold; text-decoration: underline;">trunk/res/res_musiconhold.c</a>
    <span style="font-weight: normal;">

     (Diff revision 2)

    </span>
   </th>
  </tr>
 </thead>

 <tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
  <tr>

   <td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">static int moh_scan_files(struct mohclass *class) {</pre></td>

  </tr>
 </tbody>






 
 

 <tbody>

  <tr>
    <th bgcolor="#f0f0f0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2">1104</font></th>
    <td bgcolor="#ffffff" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
    <th bgcolor="#f0f0f0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">1104</font></th>
    <td bgcolor="#ffffff" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
  </tr>

  <tr>
    <th bgcolor="#f0f0f0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2">1105</font></th>
    <td bgcolor="#ffffff" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span class="n">class</span><span class="o">-&gt;</span><span class="n">total_files</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span></pre></td>
    <th bgcolor="#f0f0f0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">1105</font></th>
    <td bgcolor="#ffffff" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">        <span class="n">class</span><span class="o">-&gt;</span><span class="n">total_files</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span></pre></td>
  </tr>

 </tbody>

</table>

  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Move this one up a line, it belongs with the ast_free, not with the getcwd.</pre>
 </blockquote>



 <p>On March 1st, 2012, 9:33 a.m., <b>junky</b> wrote:</p>
 <blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">i dont think so.
there was no { } before, so it means 
class-&gt;total_files = 0;
was called just once, after the for loop.
It doesnt make sense to call that initialisation many times, no?

I added braces though.</pre>
 </blockquote>







</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">I did not say you should move the total_files=0 to *inside* the for-loop. I just said it should move up one line.

Why? Because when I was looking for what happens if we break early from there and re-enter the function later: I saw free&#39;s, but I didn&#39;t see any nullification to prevent the free&#39;s from being done a second time. Turns out, it was there, but was leaning against the getcwd-check.

It has nothing to do with braces, just with logical ordering. I wanted:

BLOCK_THAT_FREES_STUFF_AND_SETS_IT_TO_ZERO
ENTER
BLOCK_THAT_DOES_GETCWD

and not 

BLOCK_THAT_FREES_STUFF
ENTER
BLOCK_THAT_SETS_SOMETHING_TO_ZERO_AND_DOES_GETCWD</pre>
<br />




<p>- wdoekes</p>


<br />
<p>On March 1st, 2012, 5:13 p.m., junky wrote:</p>






<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" style="background-image: url('https://reviewboard.asterisk.org/media/rb/images/review_request_box_top_bg.png'); background-position: left top; background-repeat: repeat-x; border: 1px black solid;">
 <tr>
  <td>

<div>Review request for Asterisk Developers.</div>
<div>By junky.</div>


<p style="color: grey;"><i>Updated March 1, 2012, 5:13 p.m.</i></p>




<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
 <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">This patch is to prevent many more cppcheck warnings.
</pre>
  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
 <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">used cppcheck 1.52
it compiles ;)</pre>
  </td>
 </tr>
</table>




<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">

 <li>trunk/apps/app_minivm.c <span style="color: grey">(357660)</span></li>

 <li>trunk/apps/app_osplookup.c <span style="color: grey">(357660)</span></li>

 <li>trunk/cdr/cdr_pgsql.c <span style="color: grey">(357660)</span></li>

 <li>trunk/cdr/cdr_sqlite3_custom.c <span style="color: grey">(357660)</span></li>

 <li>trunk/channels/chan_alsa.c <span style="color: grey">(357660)</span></li>

 <li>trunk/channels/chan_dahdi.c <span style="color: grey">(357660)</span></li>

 <li>trunk/channels/chan_gtalk.c <span style="color: grey">(357660)</span></li>

 <li>trunk/channels/chan_h323.c <span style="color: grey">(357660)</span></li>

 <li>trunk/channels/chan_sip.c <span style="color: grey">(357660)</span></li>

 <li>trunk/channels/chan_unistim.c <span style="color: grey">(357660)</span></li>

 <li>trunk/channels/vcodecs.c <span style="color: grey">(357660)</span></li>

 <li>trunk/codecs/codec_dahdi.c <span style="color: grey">(357660)</span></li>

 <li>trunk/codecs/codec_g726.c <span style="color: grey">(357660)</span></li>

 <li>trunk/codecs/codec_resample.c <span style="color: grey">(357660)</span></li>

 <li>trunk/formats/format_h264.c <span style="color: grey">(357660)</span></li>

 <li>trunk/funcs/func_callerid.c <span style="color: grey">(357660)</span></li>

 <li>trunk/funcs/func_devstate.c <span style="color: grey">(357660)</span></li>

 <li>trunk/funcs/func_env.c <span style="color: grey">(357660)</span></li>

 <li>trunk/funcs/func_groupcount.c <span style="color: grey">(357660)</span></li>

 <li>trunk/funcs/func_odbc.c <span style="color: grey">(357660)</span></li>

 <li>trunk/main/ast_expr2.fl <span style="color: grey">(357660)</span></li>

 <li>trunk/main/ast_expr2f.c <span style="color: grey">(357660)</span></li>

 <li>trunk/main/asterisk.c <span style="color: grey">(357660)</span></li>

 <li>trunk/main/data.c <span style="color: grey">(357660)</span></li>

 <li>trunk/res/res_config_ldap.c <span style="color: grey">(357660)</span></li>

 <li>trunk/res/res_config_sqlite3.c <span style="color: grey">(357660)</span></li>

 <li>trunk/res/res_corosync.c <span style="color: grey">(357660)</span></li>

 <li>trunk/res/res_format_attr_celt.c <span style="color: grey">(357660)</span></li>

 <li>trunk/res/res_format_attr_silk.c <span style="color: grey">(357660)</span></li>

 <li>trunk/res/res_http_post.c <span style="color: grey">(357660)</span></li>

 <li>trunk/res/res_jabber.c <span style="color: grey">(357660)</span></li>

 <li>trunk/res/res_musiconhold.c <span style="color: grey">(357660)</span></li>

 <li>trunk/res/res_odbc.c <span style="color: grey">(357660)</span></li>

 <li>trunk/res/res_phoneprov.c <span style="color: grey">(357660)</span></li>

</ul>

<p><a href="https://reviewboard.asterisk.org/r/1743/diff/" style="margin-left: 3em;">View Diff</a></p>




  </td>
 </tr>
</table>








  </div>
 </body>
</html>