[Home]

Summary:ASTERISK-04551: [patch] misc code simplifications in pbx.c
Reporter:Luigi Rizzo (rizzo)Labels:
Date Opened:2005-07-10 17:23:03Date Closed:2005-07-11 15:31:24
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Core/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) pbx.misc.diff
Description:This patch applies some minor simplifications to the code in pbx.c
to remove duplication and useless code. In particular:

- define a function, str_add(), to copy multiple strings (including
 the final NUL) into a single, suitably sized, buffer.
 This replaces 5 instances of similar code.
 I don't have a better name for the function, but the interface
 is similar to strsep() so hopefully easy to understand.

- ext_strcpy() was overly complex for what it does,
 had an extra useless 'len' argument (this is an internal API and
 the way it was used it could never overflow),
 and returned an unconvenient value (users had always to add a +1).
 The patches fixes all this.

- several places had constructs like

       if (s)
               foo(x, y, z, s);
       else
               foo(x, y, z, "");

 The patch replaces them with the more readable C construct

       foo(x, y, z, s ? s : "");

- Remove useless initializations in pbx_builtin_saynumber()

- replace a for(..) with while(..) in ast_context_verify_includes()
 to avoid writing ast_walk_context_includes() twice
 (these ast_walk_* functions are designed to be used in this way).

- remove useless variable in ast_parseable_goto().


****** ADDITIONAL INFORMATION ******

I note that in several places asterisk uses constructs equivalent to

 (some_long_variable_name_oh_yes ? some_long_variable_name_oh_yes : "" )

which would probably deserve a macro or inline function to reduce the
visual clutter.
Comments:By: Luigi Rizzo (rizzo) 2005-07-11 14:52:42

just noticed that i already reported this stuff a couple
of weeks ago, see ASTERISK-4489.
oh well... this happens when reports remain unread for ages!