From 23b4a700f47f7d5a43f1b322bd7780e1df167e3b Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Thu, 26 Nov 2009 02:09:58 +0000 Subject: Reorder option flags. Change guidelines so that example code is consistent with guidelines git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@231369 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- doc/CODING-GUIDELINES | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'doc/CODING-GUIDELINES') diff --git a/doc/CODING-GUIDELINES b/doc/CODING-GUIDELINES index 4261f2013..d1ae32dfe 100644 --- a/doc/CODING-GUIDELINES +++ b/doc/CODING-GUIDELINES @@ -435,9 +435,9 @@ functions. When making applications, always ast_strdupa(data) to a local pointer if you intend to parse the incoming data string. - if (data) + if (data) { mydata = ast_strdupa(data); - + } - Use the argument parsing macros to declare arguments and parse them, i.e.: @@ -521,10 +521,11 @@ throughout the code to log that this has occurred. The functions strdup and strndup can *not* accept a NULL argument. This results in having code like this: - if (str) + if (str) { newstr = strdup(str); - else + } else { newstr = NULL; + } However, the ast_strdup and ast_strdupa functions will happily accept a NULL argument without generating an error. The same code can be written as: @@ -666,8 +667,9 @@ const char *postfix = "post"; char *newname; char *name = "data"; -if (name && (newname = alloca(strlen(name) + strlen(prefix) + strlen(postfix) + 3))) +if (name && (newname = alloca(strlen(name) + strlen(prefix) + strlen(postfix) + 3))) { snprintf(newname, strlen(name) + strlen(prefix) + strlen(postfix) + 3, "%s/%s/%s", prefix, name, postfix); +| ...vs this alternative: @@ -677,8 +679,9 @@ char *newname; char *name = "data"; int len = 0; -if (name && (len = strlen(name) + strlen(prefix) + strlen(postfix) + 3) && (newname = alloca(len))) +if (name && (len = strlen(name) + strlen(prefix) + strlen(postfix) + 3) && (newname = alloca(len))) { snprintf(newname, len, "%s/%s/%s", prefix, name, postfix); +} * Creating new manager events? ------------------------------ -- cgit v1.2.3