aboutsummaryrefslogtreecommitdiffstats
path: root/doc/CODING-GUIDELINES
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-06-02 19:17:04 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-06-02 19:17:04 +0000
commit6e17dfcd50520ceef6d46d4a0f913e7fffba1da0 (patch)
tree10f25fb270baaf698f58c9d8a44680997df880c6 /doc/CODING-GUIDELINES
parent0bdd91b5adf3a50cc07719e5e29ae93434008331 (diff)
add a minor allocation/zeroing guideline
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5817 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'doc/CODING-GUIDELINES')
-rwxr-xr-xdoc/CODING-GUIDELINES22
1 files changed, 22 insertions, 0 deletions
diff --git a/doc/CODING-GUIDELINES b/doc/CODING-GUIDELINES
index 01a38d6f2..c237e92fd 100755
--- a/doc/CODING-GUIDELINES
+++ b/doc/CODING-GUIDELINES
@@ -192,6 +192,28 @@ output buffer will be null-terminated. Use ast_copy_string instead, which
is also slightly more efficient (and allows passing the actual buffer
size, which makes the code clearer).
+When allocating/zeroing memory for a structure, try to 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
+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.
+
== CLI Commands ==
New CLI commands should be named using the module's name, followed by a verb