Summary:ASTERISK-04489: [patch] code cleanup
Reporter:Luigi Rizzo (rizzo)Labels:
Date Opened:2005-06-27 13:30:35Date Closed:2011-06-07 14:02:40
Versions:Frequency of
Environment:Attachments:( 0) pbx.diff
Description:Misc code cleanup. In detail:

- ext_strcpy() had a useless third argument. Change its interface to
 something more useful.

- new function str_add() to append a string to a buffer and
 return a pointer after the trailing NUL in the destination.
 Used in 5 places.

- in pbx_findswitch() remove repeated calls to strlen(*ret).
 The associated simplifications also trim over 100 bytes from the code.

- add gui_string() gui_size() to return string printed to the GUI and its size.
 This collapses the various uses of the magic constants '23' and
 "Not available" in one place.

- simplify nested if's and functions with multiple return points providing
 only a single exit point (where locks are released);

- replace some *s = '\0'; s++; instances with a single *s++ = '\0' statement;

- replace some strchr() usages with the more natural (for the context) strsep()

- change instances of "if (foo) bar(x,y) else bar(x,z)" to "bar(x, foo ? y:z)"
 which is more readable ( 1 line instead of 4), less error prone,
 and produces shorter code.

- remove some useless initializations which are overwritten immediately
 afterwards with a different value
Comments:By: Kevin P. Fleming (kpfleming) 2005-07-11 17:11:37

The gui_string()/gui_size() stuff is already present in another patch.

You correctly removed the memset() before ast_copy_string() instances, but you (and the people who did the ast_copy_string() conversions) didn't catch the unnecessary setting of a null character into the buffer (which was needed with strncpy for safety).

The device state code in pbx.c and channel.c was substantially changed over the weekend, so that part of this patch is no longer applicable (sorry :-()).

I think I'd rather see the code use ast_build_string() instead of str_add(), although that will require keeping track of the buffer size... but that's a safer operation anyway.

By: Michael Jerris (mikej) 2005-07-20 19:00:43

suspended due to lack of response.  Feel free to re-open when you have updates.