[Home]

Summary:ASTERISK-04999: [patch] don't initialize buffers when it's not necessary
Reporter:Russell Bryant (russell)Labels:
Date Opened:2005-09-05 20:44:22Date Closed:2008-01-15 15:47:28.000-0600
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Core/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) buf_init.patch
Description:I went through the code and found a bunch of places where large character arrays were being initialized in cases where it was unnecessary to do so.

The changes to pbx_dundi.c also include conversions from strncpy to ast_copy_string or strcpy where appropriate.
Comments:By: Brian West (bkw918) 2005-09-05 23:32:40

This will cause valgrind to bitch up a storm.  I see no gain in removing these things.

/b

By: Russell Bryant (russell) 2005-09-07 11:28:20

Did you test it?  Is there a specific instance that it is complaining about?

Initializing huge buffers when it's not necessary creates unnecessary object code in asterisk.  The coding guidelines talk about this:

"Make sure you never use an uninitialized variable.  The compiler will
usually warn you if you do so. However, do not go too far the other way,
and needlessly initialize variables that do not require it. If the first
time you use a variable in a function is to store a value there, then
initializing it at declaration is pointless, and will generate extra
object code and data in the resulting binary with no purpose. When in doubt,
trust the compiler to tell you when you need to initialize a variable;
if it does not warn you, initialization is not needed."

By: Michael Jerris (mikej) 2005-09-07 11:32:01

we can wrap the initializations in valgrind ifdefs, then turn it on and off as needed.

By: Kevin P. Fleming (kpfleming) 2005-09-07 16:55:42

If valgrind is complaining about memory not being initialized before it is written to, it is broken.

By: Kevin P. Fleming (kpfleming) 2005-09-07 17:01:23

Committed to CVS HEAD, thanks!

By: Digium Subversion (svnbot) 2008-01-15 15:47:28.000-0600

Repository: asterisk
Revision: 6540

U   trunk/acl.c
U   trunk/app.c
U   trunk/apps/app_dial.c
U   trunk/channels/chan_iax2.c
U   trunk/channels/chan_sip.c
U   trunk/file.c
U   trunk/pbx/pbx_dundi.c
U   trunk/pbx.c
U   trunk/res/res_features.c

------------------------------------------------------------------------
r6540 | kpfleming | 2008-01-15 15:47:27 -0600 (Tue, 15 Jan 2008) | 3 lines

remove useless buffer initializations (issue ASTERISK-4999)
convert pbx_dundi to use ast_copy_string) (issue ASTERISK-4999)

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=6540