mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 04:11:08 +00:00
update guidelines to follow their own rules for whitespace (bug #4486)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5880 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -90,10 +90,10 @@ for (x=0;x<5;x++) {
|
|||||||
Don't build code like this:
|
Don't build code like this:
|
||||||
|
|
||||||
if (foo) {
|
if (foo) {
|
||||||
.... 50 lines of code ...
|
/* .... 50 lines of code ... */
|
||||||
} else {
|
} else {
|
||||||
result = 0;
|
result = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Instead, try to minimize the number of lines of code that need to be
|
Instead, try to minimize the number of lines of code that need to be
|
||||||
@@ -101,8 +101,8 @@ indented, by only indenting the shortest case of the 'if'
|
|||||||
statement, like so:
|
statement, like so:
|
||||||
|
|
||||||
if !(foo) {
|
if !(foo) {
|
||||||
result = 0;
|
result = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
.... 50 lines of code ....
|
.... 50 lines of code ....
|
||||||
@@ -125,13 +125,14 @@ options that they are in fact intended to be global.
|
|||||||
|
|
||||||
When making applications, always ast_strdupa(data) to a local pointer if
|
When making applications, always ast_strdupa(data) to a local pointer if
|
||||||
you intend to parse it.
|
you intend to parse it.
|
||||||
if(data)
|
|
||||||
mydata = ast_strdupa(data);
|
if (data)
|
||||||
|
mydata = ast_strdupa(data);
|
||||||
|
|
||||||
Always derefrence or localize pointers to things that are not yours like
|
Always derefrence or localize pointers to things that are not yours like
|
||||||
channel members in a channel that is not associated with the current
|
channel members in a channel that is not associated with the current
|
||||||
thread and for which you do not have a lock.
|
thread and for which you do not have a lock.
|
||||||
channame = ast_strdupa(otherchan->name);
|
channame = ast_strdupa(otherchan->name);
|
||||||
|
|
||||||
If you do the same or a similar operation more than 1 time, make it a
|
If you do the same or a similar operation more than 1 time, make it a
|
||||||
function or macro.
|
function or macro.
|
||||||
@@ -200,7 +201,7 @@ struct foo *tmp;
|
|||||||
|
|
||||||
tmp = malloc(sizeof(*tmp));
|
tmp = malloc(sizeof(*tmp));
|
||||||
if (tmp)
|
if (tmp)
|
||||||
memset(tmp, 0, sizeof(*tmp));
|
memset(tmp, 0, sizeof(*tmp));
|
||||||
|
|
||||||
This eliminates duplication of the 'struct foo' identifier, which makes the
|
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
|
code easier to read and also ensures that if it is copy-and-pasted it won't
|
||||||
|
Reference in New Issue
Block a user