various cleanups regarding coding guidelines issues

- malloc to ast_malloc
 - malloc + memset to ast_calloc
 - sizeof(struct foo) to sizeof(*bar)
 - remove indentation of the entire body of a function by returning immediately
   on an allocation failure
(issue #7581, tempest1)


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@38088 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Russell Bryant 19 years ago
parent f21d43ad5e
commit 5830e9cb4f

@ -280,7 +280,7 @@ static char *xml_translate(char *in, struct ast_variable *vars)
escaped++; escaped++;
} }
len = (size_t) (strlen(in) + colons * 5 + breaks * (40 + strlen(dest) + strlen(objtype)) + escaped * 10); /* foo="bar", "<response type=\"object\" id=\"dest\"", "&amp;" */ len = (size_t) (strlen(in) + colons * 5 + breaks * (40 + strlen(dest) + strlen(objtype)) + escaped * 10); /* foo="bar", "<response type=\"object\" id=\"dest\"", "&amp;" */
out = malloc(len); out = ast_malloc(len);
if (!out) if (!out)
return 0; return 0;
tmp = out; tmp = out;
@ -338,7 +338,7 @@ static char *html_translate(char *in)
breaks++; breaks++;
} }
len = strlen(in) + colons * 40 + breaks * 40; /* <tr><td></td><td></td></tr>, "<tr><td colspan=\"2\"><hr></td></tr> */ len = strlen(in) + colons * 40 + breaks * 40; /* <tr><td></td><td></td></tr>, "<tr><td colspan=\"2\"><hr></td></tr> */
out = malloc(len); out = ast_malloc(len);
if (!out) if (!out)
return 0; return 0;
tmp = out; tmp = out;
@ -1555,11 +1555,10 @@ static int action_originate(struct mansession *s, struct message *m)
l = NULL; l = NULL;
} }
if (ast_true(async)) { if (ast_true(async)) {
struct fast_originate_helper *fast = malloc(sizeof(struct fast_originate_helper)); struct fast_originate_helper *fast = ast_calloc(1, sizeof(*fast));
if (!fast) { if (!fast) {
res = -1; res = -1;
} else { } else {
memset(fast, 0, sizeof(struct fast_originate_helper));
if (!ast_strlen_zero(id)) if (!ast_strlen_zero(id))
snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s\r\n", id); snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s\r\n", id);
ast_copy_string(fast->tech, tech, sizeof(fast->tech)); ast_copy_string(fast->tech, tech, sizeof(fast->tech));
@ -2080,12 +2079,16 @@ static void *accept_thread(void *ignore)
static int append_event(const char *str, int category) static int append_event(const char *str, int category)
{ {
struct eventqent *tmp, *prev = NULL; struct eventqent *tmp, *prev = NULL;
tmp = malloc(sizeof(struct eventqent) + strlen(str)); tmp = ast_malloc(sizeof(*tmp) + strlen(str));
if (tmp) {
if (!tmp)
return -1;
ast_mutex_init(&tmp->lock); ast_mutex_init(&tmp->lock);
tmp->next = NULL; tmp->next = NULL;
tmp->category = category; tmp->category = category;
strcpy(tmp->eventdata, str); strcpy(tmp->eventdata, str);
if (master_eventq) { if (master_eventq) {
prev = master_eventq; prev = master_eventq;
while (prev->next) while (prev->next)
@ -2094,10 +2097,10 @@ static int append_event(const char *str, int category)
} else { } else {
master_eventq = tmp; master_eventq = tmp;
} }
tmp->usecount = num_sessions; tmp->usecount = num_sessions;
return 0; return 0;
}
return -1;
} }
/*! \brief manager_event: Send AMI event to client */ /*! \brief manager_event: Send AMI event to client */
@ -2218,11 +2221,10 @@ int ast_manager_register2(const char *action, int auth, int (*func)(struct manse
{ {
struct manager_action *cur; struct manager_action *cur;
cur = malloc(sizeof(struct manager_action)); cur = ast_malloc(sizeof(*cur));
if (!cur) { if (!cur)
ast_log(LOG_WARNING, "Manager: out of memory trying to register action\n");
return -1; return -1;
}
cur->action = action; cur->action = action;
cur->authority = auth; cur->authority = auth;
cur->func = func; cur->func = func;

Loading…
Cancel
Save