[asterisk-dev] bug in app_voicemail.c
Kevin P. Fleming
kpfleming at digium.com
Thu Apr 16 10:18:26 CDT 2009
Jim Capp wrote:
> 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.
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.
--
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
skype: kpfleming | jabber: kpfleming at digium.com
Check us out at www.digium.com & www.asterisk.org
More information about the asterisk-dev
mailing list