aboutsummaryrefslogtreecommitdiffstats
path: root/channels
diff options
context:
space:
mode:
authorbbryant <bbryant@f38db490-d61c-443f-a65b-d21fe96a405b>2008-07-08 16:40:28 +0000
committerbbryant <bbryant@f38db490-d61c-443f-a65b-d21fe96a405b>2008-07-08 16:40:28 +0000
commit0110f8c87a0481038e3673640c387417fb339b4c (patch)
treedf03af827ea95734e2906e4737660d983e3e0b01 /channels
parentcdea52a3def39e3b06cb2ef6f0ca88a4c5f710a8 (diff)
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/trunk@129045 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_dahdi.c14
-rw-r--r--channels/chan_iax2.c30
-rw-r--r--channels/chan_sip.c9
-rw-r--r--channels/h323/ast_h323.cxx4
-rw-r--r--channels/iax2-provision.c4
5 files changed, 34 insertions, 27 deletions
diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 3d8c05e7b..34162ea5f 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -1344,7 +1344,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;
}
@@ -1697,7 +1697,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;
@@ -1709,7 +1709,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;
@@ -1731,7 +1731,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;
@@ -1743,7 +1743,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;
@@ -6891,7 +6891,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;
@@ -7040,7 +7040,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 1a749b644..e733ddce9 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -2788,23 +2788,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);
@@ -6527,9 +6531,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);
@@ -11440,7 +11445,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);
@@ -11455,12 +11460,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;
}
@@ -11513,9 +11518,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 4f71133d2..bdaefc0f2 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -2630,7 +2630,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;
@@ -5705,9 +5705,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;
}
@@ -13104,7 +13105,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);
@@ -13965,7 +13966,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 4a5281c05..8bdfdbfb7 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;