diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-01-21 08:01:24 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-01-21 08:01:24 +0000 |
commit | 7d766728281dd1b6eb53a4ec8d0e8e5d6312835c (patch) | |
tree | 89a2d90f97c6d6760bf7ce986c41187f89e07c32 | |
parent | 8b09090fc140885813db6e0f568f854143570230 (diff) |
remove some useless checks of the result of ast_strdupa
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@8378 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r-- | channels/chan_agent.c | 14 | ||||
-rw-r--r-- | channels/chan_iax2.c | 48 | ||||
-rw-r--r-- | channels/chan_sip.c | 79 |
3 files changed, 36 insertions, 105 deletions
diff --git a/channels/chan_agent.c b/channels/chan_agent.c index 68652b1e7..94a6965e4 100644 --- a/channels/chan_agent.c +++ b/channels/chan_agent.c @@ -329,10 +329,6 @@ static struct agent_pvt *add_agent(char *agent, int pending) struct agent_pvt *p, *prev; parse = ast_strdupa(agent); - if (!parse) { - ast_log(LOG_ERROR, "Out of memory!\n"); - return NULL; - } /* Extract username (agt), password and name from agent (args). */ AST_NONSTANDARD_APP_ARGS(args, parse, ','); @@ -1767,11 +1763,7 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode) LOCAL_USER_ADD(u); - if (!(parse = ast_strdupa(data))) { - ast_log(LOG_ERROR, "Out of memory!\n"); - LOCAL_USER_REMOVE(u); - return -1; - } + parse = ast_strdupa(data); AST_STANDARD_APP_ARGS(args, parse); @@ -2511,10 +2503,6 @@ static char *function_agent(struct ast_channel *chan, char *cmd, char *data, cha } item = ast_strdupa(data); - if (!item) { - ast_log(LOG_ERROR, "Out of memory!\n"); - return buf; - } agentid = strsep(&item, ":"); if (!item) diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 6238366c8..30e010b0c 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -2784,12 +2784,10 @@ static int create_addr(const char *peername, struct sockaddr_in *sin, struct cre char *key = NULL; family = ast_strdupa(peer->dbsecret); - if (family) { - key = strchr(family, '/'); - if (key) - *key++ = '\0'; - } - if (!family || !key || ast_db_get(family, key, cai->secret, sizeof(cai->secret))) { + key = strchr(family, '/'); + if (key) + *key++ = '\0'; + if (!key || ast_db_get(family, key, cai->secret, sizeof(cai->secret))) { ast_log(LOG_WARNING, "Unable to retrieve database password for family/key '%s'!\n", peer->dbsecret); if (ast_test_flag(peer, IAX_TEMPONLY)) destroy_peer(peer); @@ -3906,9 +3904,8 @@ static int decrypt_frame(int callno, struct ast_iax2_full_hdr *fh, struct ast_fr unsigned char digest[16]; char *tmppw, *stringp; - tmppw = ast_strdupa(iaxs[callno]->secret); - stringp = tmppw; - while((tmppw = strsep(&stringp, ";"))) { + stringp = ast_strdupa(iaxs[callno]->secret); + while ((tmppw = strsep(&stringp, ";"))) { MD5Init(&md5); MD5Update(&md5, (unsigned char *)iaxs[callno]->challenge, strlen(iaxs[callno]->challenge)); MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw)); @@ -4855,14 +4852,10 @@ static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies if (!ast_strlen_zero(user->dbsecret)) { char *family, *key=NULL; family = ast_strdupa(user->dbsecret); - if (family) { - key = strchr(family, '/'); - if (key) { - *key = '\0'; - key++; - } - } - if (!family || !key || ast_db_get(family, key, iaxs[callno]->secret, sizeof(iaxs[callno]->secret))) { + key = strchr(family, '/'); + if (key) + *key++ = '\0'; + if (!key || ast_db_get(family, key, iaxs[callno]->secret, sizeof(iaxs[callno]->secret))) { ast_log(LOG_WARNING, "Unable to retrieve database password for family/key '%s'!\n", user->dbsecret); if (ast_test_flag(user, IAX_TEMPONLY)) { destroy_user(user); @@ -4968,9 +4961,8 @@ static int authenticate_verify(struct chan_iax2_pvt *p, struct iax_ies *ies) unsigned char digest[16]; char *tmppw, *stringp; - tmppw = ast_strdupa(p->secret); - stringp = tmppw; - while((tmppw = strsep(&stringp, ";"))) { + stringp = ast_strdupa(p->secret); + while ((tmppw = strsep(&stringp, ";"))) { MD5Init(&md5); MD5Update(&md5, (unsigned char *)p->challenge, strlen(p->challenge)); MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw)); @@ -5098,9 +5090,8 @@ static int register_verify(int callno, struct sockaddr_in *sin, struct iax_ies * unsigned char digest[16]; char *tmppw, *stringp; - tmppw = ast_strdupa(p->secret); - stringp = tmppw; - while((tmppw = strsep(&stringp, ";"))) { + stringp = ast_strdupa(p->secret); + while ((tmppw = strsep(&stringp, ";"))) { MD5Init(&md5); MD5Update(&md5, (unsigned char *)iaxs[callno]->challenge, strlen(iaxs[callno]->challenge)); MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw)); @@ -8034,10 +8025,6 @@ static int peer_set_srcaddr(struct iax2_peer *peer, const char *srcaddr) char *portstr; tmp = ast_strdupa(srcaddr); - if (!tmp) { - ast_log(LOG_WARNING, "Out of memory!\n"); - return -1; - } addr = strsep(&tmp, ":"); portstr = tmp; @@ -8335,7 +8322,7 @@ static struct iax2_user *build_user(const char *name, struct ast_variable *v, in user->ha = ast_append_ha(v->name, v->value, user->ha); } else if (!strcasecmp(v->name, "setvar")) { varname = ast_strdupa(v->value); - if (varname && (varval = strchr(varname,'='))) { + if ((varval = strchr(varname,'='))) { *varval = '\0'; varval++; if((tmpvar = ast_variable_new(varname, varval))) { @@ -9174,10 +9161,7 @@ static char *function_iaxpeer(struct ast_channel *chan, char *cmd, char *data, c char *peername, *colname; char iabuf[INET_ADDRSTRLEN]; - if (!(peername = ast_strdupa(data))) { - ast_log(LOG_ERROR, "Memory Error!\n"); - return ret; - } + peername = ast_strdupa(data); /* if our channel, return the IP address of the endpoint of current channel */ if (!strcmp(peername,"CURRENTCHANNEL")) { diff --git a/channels/chan_sip.c b/channels/chan_sip.c index fd78084b1..761e92a02 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -1860,12 +1860,9 @@ static int create_addr_from_peer(struct sip_pvt *r, struct sip_peer *peer) char *tmpcall; char *c; tmpcall = ast_strdupa(r->callid); - if (tmpcall) { - c = strchr(tmpcall, '@'); - if (c) { - *c = '\0'; - ast_string_field_build(r, callid, "%s@%s", tmpcall, peer->fromdomain); - } + if ((c = strchr(tmpcall, '@'))) { + *c = '\0'; + ast_string_field_build(r, callid, "%s@%s", tmpcall, peer->fromdomain); } } if (ast_strlen_zero(r->tohost)) { @@ -7057,12 +7054,8 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipme if ((c = strchr(of, ':'))) *c = '\0'; tmp = ast_strdupa(of); - if (tmp) { - ast_shrink_phone_number(tmp); - ast_string_field_set(p, cid_num, tmp); - } else { - ast_string_field_set(p, cid_num, of); - } + ast_shrink_phone_number(tmp); + ast_string_field_set(p, cid_num, tmp); } if (ast_strlen_zero(of)) return 0; @@ -7087,12 +7080,8 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipme if (*calleridname) ast_string_field_set(p, cid_name, calleridname); tmp = ast_strdupa(rpid_num); - if (tmp) { - ast_shrink_phone_number(tmp); - ast_string_field_set(p, cid_num, tmp); - } else { - ast_string_field_set(p, cid_num, rpid_num); - } + ast_shrink_phone_number(tmp); + ast_string_field_set(p, cid_num, tmp); } if (p->rtp) { @@ -7119,12 +7108,8 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipme ast_string_field_set(p, context, user->context); if (!ast_strlen_zero(user->cid_num) && !ast_strlen_zero(p->cid_num)) { char *tmp = ast_strdupa(user->cid_num); - if (tmp) { - ast_shrink_phone_number(tmp); - ast_string_field_set(p, cid_num, tmp); - } else { - ast_string_field_set(p, cid_num, user->cid_num); - } + ast_shrink_phone_number(tmp); + ast_string_field_set(p, cid_num, tmp); } if (!ast_strlen_zero(user->cid_name) && !ast_strlen_zero(p->cid_num)) ast_string_field_set(p, cid_name, user->cid_name); @@ -7186,12 +7171,8 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipme char *tmp = ast_strdupa(rpid_num); if (*calleridname) ast_string_field_set(p, cid_name, calleridname); - if (tmp) { - ast_shrink_phone_number(tmp); - ast_string_field_set(p, cid_num, tmp); - } else { - ast_string_field_set(p, cid_num, rpid_num); - } + ast_shrink_phone_number(tmp); + ast_string_field_set(p, cid_num, tmp); } if (p->rtp) { ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE)); @@ -7236,12 +7217,8 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipme } if (!ast_strlen_zero(peer->cid_num) && !ast_strlen_zero(p->cid_num)) { char *tmp = ast_strdupa(peer->cid_num); - if (tmp) { - ast_shrink_phone_number(tmp); - ast_string_field_set(p, cid_num, tmp); - } else { - ast_string_field_set(p, cid_num, peer->cid_num); - } + ast_shrink_phone_number(tmp); + ast_string_field_set(p, cid_num, tmp); } if (!ast_strlen_zero(peer->cid_name) && !ast_strlen_zero(p->cid_name)) ast_string_field_set(p, cid_name, peer->cid_name); @@ -9292,10 +9269,7 @@ static char *function_sippeer(struct ast_channel *chan, char *cmd, char *data, c char *peername, *colname; char iabuf[INET_ADDRSTRLEN]; - if (!(peername = ast_strdupa(data))) { - ast_log(LOG_ERROR, "Memory Error!\n"); - return ret; - } + peername = ast_strdupa(data); if ((colname = strchr(peername, ':'))) { *colname = '\0'; @@ -11953,7 +11927,7 @@ static struct sip_user *build_user(const char *name, struct ast_variable *v, int ast_copy_string(user->subscribecontext, v->value, sizeof(user->subscribecontext)); } else if (!strcasecmp(v->name, "setvar")) { varname = ast_strdupa(v->value); - if (varname && (varval = strchr(varname,'='))) { + if ((varval = strchr(varname,'='))) { *varval = '\0'; varval++; if ((tmpvar = ast_variable_new(varname, varval))) { @@ -12257,7 +12231,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int } else if (!strcasecmp(v->name, "setvar")) { /* Set peer channel variable */ varname = ast_strdupa(v->value); - if (varname && (varval = strchr(varname,'='))) { + if ((varval = strchr(varname,'='))) { *varval = '\0'; varval++; if ((tmpvar = ast_variable_new(varname, varval))) { @@ -12848,10 +12822,6 @@ static int sip_sipredirect(struct sip_pvt *p, const char *dest) char tmp[80]; cdest = ast_strdupa(dest); - if (!cdest) { - ast_log(LOG_ERROR, "Problem allocating the memory\n"); - return 0; - } extension = strsep(&cdest, "@"); host = strsep(&cdest, ":"); port = strsep(&cdest, ":"); @@ -12869,28 +12839,17 @@ static int sip_sipredirect(struct sip_pvt *p, const char *dest) return 0; } if ((localtmp = strstr(tmp, "sip:")) && (localtmp = strchr(localtmp, '@'))) { - char lhost[80], lport[80]; - memset(lhost, 0, sizeof(lhost)); - memset(lport, 0, sizeof(lport)); + char lhost[80] = "", lport[80] = ""; localtmp++; /* This is okey because lhost and lport are as big as tmp */ sscanf(localtmp, "%[^<>:; ]:%[^<>:; ]", lhost, lport); - if (!strlen(lhost)) { + if (ast_strlen_zero(lhost)) { ast_log(LOG_ERROR, "Can't find the host address\n"); return 0; } host = ast_strdupa(lhost); - if (!host) { - ast_log(LOG_ERROR, "Problem allocating the memory\n"); - return 0; - } - if (!ast_strlen_zero(lport)) { + if (!ast_strlen_zero(lport)) port = ast_strdupa(lport); - if (!port) { - ast_log(LOG_ERROR, "Problem allocating the memory\n"); - return 0; - } - } } } |