[svn-commits] branch russell/ast_malloc - r7632 /team/russell/ast_malloc/doc/CODING-GUIDELINES

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sun Dec 25 20:30:21 CST 2005


Author: russell
Date: Sun Dec 25 20:30:19 2005
New Revision: 7632

URL: http://svn.digium.com/view/asterisk?rev=7632&view=rev
Log:
update coding guidelines

Modified:
    team/russell/ast_malloc/doc/CODING-GUIDELINES

Modified: team/russell/ast_malloc/doc/CODING-GUIDELINES
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/doc/CODING-GUIDELINES?rev=7632&r1=7631&r2=7632&view=diff
==============================================================================
--- team/russell/ast_malloc/doc/CODING-GUIDELINES (original)
+++ team/russell/ast_malloc/doc/CODING-GUIDELINES Sun Dec 25 20:30:19 2005
@@ -349,27 +349,24 @@
 arrangements and produce unexpected behavior.
 
 -Allocations for structures
-When allocating/zeroing memory for a structure, try to use code like this:
+When allocating/zeroing memory for a structure, use code like this:
 
 struct foo *tmp;
 
 ...
 
-tmp = malloc(sizeof(*tmp));
-if (tmp)
-	memset(tmp, 0, sizeof(*tmp));
-
-This eliminates duplication of the 'struct foo' identifier, which makes the
+tmp = ast_calloc(1, sizeof(*tmp));
+
+This will allocate and zero the memory in a single operation. 
+
+Avoid the combination of ast_malloc() and memset().  Instead, always use
+ast_calloc().  In the case that uninitialized memory is acceptable, there should
+be a comment in the code that states why this is the case.
+
+This also eliminates duplication of the 'struct foo' identifier, which makes the
 code easier to read and also ensures that if it is copy-and-pasted it won't
-require as much editing. In fact, you can even use:
-
-struct foo *tmp;
-
-...
-
-tmp = calloc(1, sizeof(*tmp));
-
-This will allocate and zero the memory in a single operation.
+require as much editing.
+
 
 * CLI Commands
 --------------



More information about the svn-commits mailing list