remove some useless checks of the result of ast_strdupa
authorRussell Bryant <russell@russellbryant.com>
Sat, 21 Jan 2006 08:01:24 +0000 (08:01 +0000)
committerRussell Bryant <russell@russellbryant.com>
Sat, 21 Jan 2006 08:01:24 +0000 (08:01 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8378 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_agent.c
channels/chan_iax2.c
channels/chan_sip.c

index 68652b1..94a6965 100644 (file)
@@ -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)
index 6238366..30e010b 100644 (file)
@@ -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")) {
index fd78084..761e92a 100644 (file)
@@ -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;
-                               }
-                       }
                }
        }