diff options
author | bbryant <bbryant@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-07-08 16:41:31 +0000 |
---|---|---|
committer | bbryant <bbryant@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-07-08 16:41:31 +0000 |
commit | 3b5c2f2ec9a1f1b932a72c54ec99f2ade7b874e5 (patch) | |
tree | 2e4756c8d1b95bdec564a84466c61973aa5e336e /channels | |
parent | b2d0a411d289307a4a22e2647d0ad5540542de01 (diff) |
Merged revisions 129045 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
........
r129045 | bbryant | 2008-07-08 11:40:28 -0500 (Tue, 08 Jul 2008) | 7 lines
Janitor project to convert sizeof to ARRAY_LEN macro.
(closes issue #13002)
Reported by: caio1982
Patches:
janitor_arraylen5.diff uploaded by caio1982 (license 22)
........
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@129046 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_dahdi.c | 14 | ||||
-rw-r--r-- | channels/chan_iax2.c | 30 | ||||
-rw-r--r-- | channels/chan_sip.c | 9 | ||||
-rw-r--r-- | channels/h323/ast_h323.cxx | 4 | ||||
-rw-r--r-- | channels/iax2-provision.c | 4 |
5 files changed, 34 insertions, 27 deletions
diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c index 3d1c9c407..c83d1f0af 100644 --- a/channels/chan_dahdi.c +++ b/channels/chan_dahdi.c @@ -1336,7 +1336,7 @@ static struct { static char *alarm2str(int alarm) { int x; - for (x = 0; x < sizeof(alarms) / sizeof(alarms[0]); x++) { + for (x = 0; x < ARRAY_LEN(alarms); x++) { if (alarms[x].alarm & alarm) return alarms[x].name; } @@ -1695,7 +1695,7 @@ static void fill_txgain(struct dahdi_gains *g, float gain, int law) switch (law) { case DAHDI_LAW_ALAW: - for (j = 0; j < (sizeof(g->txgain) / sizeof(g->txgain[0])); j++) { + for (j = 0; j < ARRAY_LEN(g->txgain); j++) { if (gain) { k = (int) (((float) AST_ALAW(j)) * linear_gain); if (k > 32767) k = 32767; @@ -1707,7 +1707,7 @@ static void fill_txgain(struct dahdi_gains *g, float gain, int law) } break; case DAHDI_LAW_MULAW: - for (j = 0; j < (sizeof(g->txgain) / sizeof(g->txgain[0])); j++) { + for (j = 0; j < ARRAY_LEN(g->txgain); j++) { if (gain) { k = (int) (((float) AST_MULAW(j)) * linear_gain); if (k > 32767) k = 32767; @@ -1729,7 +1729,7 @@ static void fill_rxgain(struct dahdi_gains *g, float gain, int law) switch (law) { case DAHDI_LAW_ALAW: - for (j = 0; j < (sizeof(g->rxgain) / sizeof(g->rxgain[0])); j++) { + for (j = 0; j < ARRAY_LEN(g->rxgain); j++) { if (gain) { k = (int) (((float) AST_ALAW(j)) * linear_gain); if (k > 32767) k = 32767; @@ -1741,7 +1741,7 @@ static void fill_rxgain(struct dahdi_gains *g, float gain, int law) } break; case DAHDI_LAW_MULAW: - for (j = 0; j < (sizeof(g->rxgain) / sizeof(g->rxgain[0])); j++) { + for (j = 0; j < ARRAY_LEN(g->rxgain); j++) { if (gain) { k = (int) (((float) AST_MULAW(j)) * linear_gain); if (k > 32767) k = 32767; @@ -6899,7 +6899,7 @@ static void *ss_thread(void *data) len = 0; distMatches = 0; /* Clear the current ring data array so we dont have old data in it. */ - for (receivedRingT = 0; receivedRingT < (sizeof(curRingData) / sizeof(curRingData[0])); receivedRingT++) + for (receivedRingT = 0; receivedRingT < ARRAY_LEN(curRingData); receivedRingT++) curRingData[receivedRingT] = 0; receivedRingT = 0; counter = 0; @@ -7048,7 +7048,7 @@ static void *ss_thread(void *data) len = 0; distMatches = 0; /* Clear the current ring data array so we dont have old data in it. */ - for (receivedRingT = 0; receivedRingT < (sizeof(curRingData) / sizeof(curRingData[0])); receivedRingT++) + for (receivedRingT = 0; receivedRingT < ARRAY_LEN(curRingData); receivedRingT++) curRingData[receivedRingT] = 0; receivedRingT = 0; counter = 0; diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index f0ac68d3e..a4c977b83 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -2770,23 +2770,27 @@ static char *handle_cli_iax2_show_cache(struct ast_cli_entry *e, int cmd, struct if (dp->flags & CACHE_FLAG_UNKNOWN) strncat(tmp, "UNKNOWN|", sizeof(tmp) - strlen(tmp) - 1); /* Trim trailing pipe */ - if (!ast_strlen_zero(tmp)) + if (!ast_strlen_zero(tmp)) { tmp[strlen(tmp) - 1] = '\0'; - else + } else { ast_copy_string(tmp, "(none)", sizeof(tmp)); + } y = 0; pc = strchr(dp->peercontext, '@'); - if (!pc) + if (!pc) { pc = dp->peercontext; - else + } else { pc++; - for (x = 0; x < sizeof(dp->waiters) / sizeof(dp->waiters[0]); x++) + } + for (x = 0; x < ARRAY_LEN(dp->waiters); x++) { if (dp->waiters[x] > -1) y++; - if (s > 0) + } + if (s > 0) { ast_cli(a->fd, "%-20.20s %-12.12s %-9d %-8d %s\n", pc, dp->exten, s, y, tmp); - else + } else { ast_cli(a->fd, "%-20.20s %-12.12s %-9.9s %-8d %s\n", pc, dp->exten, "(expired)", y, tmp); + } } AST_LIST_LOCK(&dpcache); @@ -6474,9 +6478,10 @@ static int complete_dpreply(struct chan_iax2_pvt *pvt, struct iax_ies *ies) dp->flags |= matchmore; } /* Wake up waiters */ - for (x=0;x<sizeof(dp->waiters) / sizeof(dp->waiters[0]); x++) + for (x = 0; x < ARRAY_LEN(dp->waiters); x++) { if (dp->waiters[x] > -1) write(dp->waiters[x], "asdf", 4); + } } AST_LIST_TRAVERSE_SAFE_END; AST_LIST_UNLOCK(&dpcache); @@ -11336,7 +11341,7 @@ static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *dat /* Expires in 30 mins by default */ dp->expiry.tv_sec += iaxdefaultdpcache; dp->flags = CACHE_FLAG_PENDING; - for (x=0;x<sizeof(dp->waiters) / sizeof(dp->waiters[0]); x++) + for (x = 0; x < ARRAY_LEN(dp->waiters); x++) dp->waiters[x] = -1; /* Insert into the lists */ AST_LIST_INSERT_TAIL(&dpcache, dp, cache_list); @@ -11351,12 +11356,12 @@ static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *dat if (dp->flags & CACHE_FLAG_PENDING) { /* Okay, here it starts to get nasty. We need a pipe now to wait for a reply to come back so long as it's pending */ - for (x=0;x<sizeof(dp->waiters) / sizeof(dp->waiters[0]); x++) { + for (x = 0; x < ARRAY_LEN(dp->waiters); x++) { /* Find an empty slot */ if (dp->waiters[x] < 0) break; } - if (x >= sizeof(dp->waiters) / sizeof(dp->waiters[0])) { + if (x >= ARRAY_LEN(dp->waiters)) { ast_log(LOG_WARNING, "No more waiter positions available\n"); return NULL; } @@ -11409,9 +11414,10 @@ static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *dat /* Expire after only 60 seconds now. This is designed to help reduce backlog in heavily loaded systems without leaving it unavailable once the server comes back online */ dp->expiry.tv_sec = dp->orig.tv_sec + 60; - for (x=0;x<sizeof(dp->waiters) / sizeof(dp->waiters[0]); x++) + for (x = 0; x < ARRAY_LEN(dp->waiters); x++) { if (dp->waiters[x] > -1) write(dp->waiters[x], "asdf", 4); + } } } /* Our caller will obtain the rest */ diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 3833476bf..37769827c 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -2429,7 +2429,7 @@ static unsigned int parse_sip_options(struct sip_pvt *pvt, const char *supported next = ast_skip_blanks(next); if (sipdebug) ast_debug(3, "Found SIP option: -%s-\n", next); - for (i=0; i < (sizeof(sip_options) / sizeof(sip_options[0])); i++) { + for (i = 0; i < ARRAY_LEN(sip_options); i++) { if (!strcasecmp(next, sip_options[i].text)) { profile |= sip_options[i].id; found = TRUE; @@ -5526,9 +5526,10 @@ static const char *find_alias(const char *name, const char *_default) }; int x; - for (x=0; x<sizeof(aliases) / sizeof(aliases[0]); x++) + for (x = 0; x < ARRAY_LEN(aliases); x++) { if (!strcasecmp(aliases[x].fullname, name)) return aliases[x].shortname; + } return _default; } @@ -12693,7 +12694,7 @@ static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct ast_cli(fd, " SIP Options : "); if (peer->sipoptions) { int lastoption = -1; - for (x=0 ; (x < (sizeof(sip_options) / sizeof(sip_options[0]))); x++) { + for (x = 0 ; x < ARRAY_LEN(sip_options); x++) { if (sip_options[x].id != lastoption) { if (peer->sipoptions & sip_options[x].id) ast_cli(fd, "%s ", sip_options[x].text); @@ -13518,7 +13519,7 @@ static char *sip_show_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_a ast_cli(a->fd, " SIP Options: "); if (cur->sipoptions) { int x; - for (x=0 ; (x < (sizeof(sip_options) / sizeof(sip_options[0]))); x++) { + for (x = 0 ; x < ARRAY_LEN(sip_options); x++) { if (cur->sipoptions & sip_options[x].id) ast_cli(a->fd, "%s ", sip_options[x].text); } diff --git a/channels/h323/ast_h323.cxx b/channels/h323/ast_h323.cxx index 48b876aab..a55a89574 100644 --- a/channels/h323/ast_h323.cxx +++ b/channels/h323/ast_h323.cxx @@ -970,7 +970,7 @@ static BOOL EmbedCiscoTunneledInfo(H323SignalPDU &pdu) Q931 tmpQ931; Q931 &q931 = pdu.GetQ931(); - for(unsigned i = 0; i < (sizeof(codes) / sizeof(codes[0])); ++i) { + for(unsigned i = 0; i < ARRAY_LEN(codes); ++i) { if (q931.HasIE(codes[i].ie)) { tmpQ931.SetIE(codes[i].ie, q931.GetIE(codes[i].ie)); if (!codes[i].dontDelete) @@ -1104,7 +1104,7 @@ static BOOL EmbedQSIGTunneledInfo(H323SignalPDU &pdu) q931.Encode(message); /* Remove non-standard IEs */ - for(unsigned i = 0; i < (sizeof(codes) / sizeof(codes[0])); ++i) { + for(unsigned i = 0; i < ARRAY_LEN(codes); ++i) { if (q931.HasIE(codes[i])) { q931.RemoveIE(codes[i]); } diff --git a/channels/iax2-provision.c b/channels/iax2-provision.c index c34665dbe..a0b52aaee 100644 --- a/channels/iax2-provision.c +++ b/channels/iax2-provision.c @@ -87,7 +87,7 @@ char *iax_provflags2str(char *buf, int buflen, unsigned int flags) buf[0] = '\0'; - for (x = 0; x < sizeof(iax_flags) / sizeof(iax_flags[0]); x++) { + for (x = 0; x < ARRAY_LEN(iax_flags); x++) { if (flags & iax_flags[x].value){ strncat(buf, iax_flags[x].name, buflen - strlen(buf) - 1); strncat(buf, ",", buflen - strlen(buf) - 1); @@ -116,7 +116,7 @@ static unsigned int iax_str2flags(const char *buf) else len = 0; found = 0; - for (x=0;x<sizeof(iax_flags) / sizeof(iax_flags[0]); x++) { + for (x = 0; x < ARRAY_LEN(iax_flags); x++) { if ((len && !strncasecmp(iax_flags[x].name, buf, len)) || (!len && !strcasecmp(iax_flags[x].name, buf))) { flags |= iax_flags[x].value; |