<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Kevin,<br>
<br>
&nbsp;&nbsp;&nbsp; You are, of course, assuming that app_voicemail is compiled as a
module.&nbsp; When it is compiled as part of the asterisk binary, however,
the little nasty rears its ugly head.<br>
<br>
Jim<br>
<br>
<br>
<blockquote
 cite="mid:mailman.9270.1239895999.3386.asterisk-dev@lists.digium.com"
 type="cite"><br>
  <hr size="4" width="90%"><br>
  <table class="header-part1" border="0" cellpadding="0" cellspacing="0"
 width="100%">
    <tbody>
      <tr>
        <td>
        <div class="headerdisplayname" style="display: inline;">Subject:
        </div>
Re: [asterisk-dev] bug in app_voicemail.c</td>
      </tr>
      <tr>
        <td>
        <div class="headerdisplayname" style="display: inline;">From: </div>
"Kevin P. Fleming" <a class="moz-txt-link-rfc2396E" href="mailto:kpfleming@digium.com">&lt;kpfleming@digium.com&gt;</a></td>
      </tr>
      <tr>
        <td>
        <div class="headerdisplayname" style="display: inline;">Date: </div>
Thu, 16 Apr 2009 10:18:26 -0500</td>
      </tr>
      <tr>
        <td>
        <div class="headerdisplayname" style="display: inline;">To: </div>
Asterisk Developers Mailing List <a class="moz-txt-link-rfc2396E" href="mailto:asterisk-dev@lists.digium.com">&lt;asterisk-dev@lists.digium.com&gt;</a></td>
      </tr>
    </tbody>
  </table>
  <table class="header-part2" border="0" cellpadding="0" cellspacing="0"
 width="100%">
    <tbody>
      <tr>
        <td>
        <div class="headerdisplayname" style="display: inline;">To: </div>
Asterisk Developers Mailing List <a class="moz-txt-link-rfc2396E" href="mailto:asterisk-dev@lists.digium.com">&lt;asterisk-dev@lists.digium.com&gt;</a></td>
      </tr>
    </tbody>
  </table>
  <br>
  <pre wrap="">Jim Capp wrote:

  </pre>
  <blockquote type="cite">
    <pre wrap="">The problem is that since my_umask is not declared static, compilers are
not required to persist its value. As such, some highly optimized
compilers will assign it a cpu register rather than variable space on
the stack. Since my_umask is only set during module load, subsequent
uses of my_umask are unreliable as the register will surely have been
overwritten prior to its next use.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
This is incorrect. Since 'my_umask' is a module level variable (file
scope) its value *must* be preserved across function calls, since all
functions within that module share that variable. In addition, since it
is not static, then it becomes an exported symbol from that module and
could be accessed from other modules (compilation units). Without the
compiler being told otherwise, it *must* treat the variable this way,
including placing the symbol for this variable into the run-time symbol
table for the module for the linker to be able to resolve references to
at runtime. With all of this, I do not see how it could ever be placed
into a register, and that's not even taking into account the fact that
the variable can be accessed from multiple functions in app_voicemail
that can be called from various different call paths, and it would not
be possible to ensure that the register that had been assigned was
preserved through all those code paths.

Now, in spite of all of that, making this variable static *is* the right
thing to do, since it does not need to be exported (in fact, for nearly
all modules in Asterisk, file-scope variables should *always* be
static). If this fixes the bug that's great, but I without more evidence
I don't see how the reason why it fixes the bug is what you have described.

  </pre>
</blockquote>
</body>
</html>