diff options
author | bbryant <bbryant@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-07-08 16:40:28 +0000 |
---|---|---|
committer | bbryant <bbryant@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-07-08 16:40:28 +0000 |
commit | 0110f8c87a0481038e3673640c387417fb339b4c (patch) | |
tree | df03af827ea95734e2906e4737660d983e3e0b01 /main | |
parent | cdea52a3def39e3b06cb2ef6f0ca88a4c5f710a8 (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 'main')
-rw-r--r-- | main/acl.c | 4 | ||||
-rw-r--r-- | main/callerid.c | 6 | ||||
-rw-r--r-- | main/channel.c | 2 | ||||
-rw-r--r-- | main/frame.c | 28 | ||||
-rw-r--r-- | main/logger.c | 4 | ||||
-rw-r--r-- | main/manager.c | 6 | ||||
-rw-r--r-- | main/pbx.c | 4 | ||||
-rw-r--r-- | main/rtp.c | 4 |
8 files changed, 29 insertions, 29 deletions
diff --git a/main/acl.c b/main/acl.c index d903851ee..54747de5f 100644 --- a/main/acl.c +++ b/main/acl.c @@ -434,7 +434,7 @@ int ast_str2tos(const char *value, unsigned int *tos) return 0; } - for (x = 0; x < sizeof(dscp_pool1) / sizeof(dscp_pool1[0]); x++) { + for (x = 0; x < ARRAY_LEN(dscp_pool1); x++) { if (!strcasecmp(value, dscp_pool1[x].name)) { *tos = dscp_pool1[x].space << 2; return 0; @@ -448,7 +448,7 @@ const char *ast_tos2str(unsigned int tos) { unsigned int x; - for (x = 0; x < sizeof(dscp_pool1) / sizeof(dscp_pool1[0]); x++) { + for (x = 0; x < ARRAY_LEN(dscp_pool1); x++) { if (dscp_pool1[x].space == (tos >> 2)) return dscp_pool1[x].name; } diff --git a/main/callerid.c b/main/callerid.c index 1e9bcad42..c8c3afcb6 100644 --- a/main/callerid.c +++ b/main/callerid.c @@ -1099,7 +1099,7 @@ int ast_parse_caller_presentation(const char *data) { int i; - for (i = 0; i < ((sizeof(pres_types) / sizeof(pres_types[0]))); i++) { + for (i = 0; i < ARRAY_LEN(pres_types); i++) { if (!strcasecmp(pres_types[i].name, data)) return pres_types[i].val; } @@ -1115,7 +1115,7 @@ const char *ast_describe_caller_presentation(int data) { int i; - for (i = 0; i < ((sizeof(pres_types) / sizeof(pres_types[0]))); i++) { + for (i = 0; i < ARRAY_LEN(pres_types); i++) { if (pres_types[i].val == data) return pres_types[i].description; } @@ -1131,7 +1131,7 @@ const char *ast_named_caller_presentation(int data) { int i; - for (i = 0; i < ((sizeof(pres_types) / sizeof(pres_types[0]))); i++) { + for (i = 0; i < ARRAY_LEN(pres_types); i++) { if (pres_types[i].val == data) return pres_types[i].name; } diff --git a/main/channel.c b/main/channel.c index cbfe8ffca..443715549 100644 --- a/main/channel.c +++ b/main/channel.c @@ -752,7 +752,7 @@ int ast_best_codec(int fmts) fmts &= AST_FORMAT_AUDIO_MASK; /* Find the first preferred codec in the format given */ - for (x = 0; x < (sizeof(prefs) / sizeof(prefs[0]) ); x++) { + for (x = 0; x < ARRAY_LEN(prefs); x++) { if (fmts & prefs[x]) return prefs[x]; } diff --git a/main/frame.c b/main/frame.c index f92628e28..29bf66a9d 100644 --- a/main/frame.c +++ b/main/frame.c @@ -503,7 +503,7 @@ struct ast_format_list *ast_get_format_list_index(int index) struct ast_format_list *ast_get_format_list(size_t *size) { - *size = (sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0])); + *size = ARRAY_LEN(AST_FORMAT_LIST); return AST_FORMAT_LIST; } @@ -511,7 +511,7 @@ char* ast_getformatname(int format) { int x; char *ret = "unknown"; - for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { + for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) { if (AST_FORMAT_LIST[x].bits == format) { ret = AST_FORMAT_LIST[x].name; break; @@ -533,7 +533,7 @@ char *ast_getformatname_multiple(char *buf, size_t size, int format) end += len; size -= len; start = end; - for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { + for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) { if (AST_FORMAT_LIST[x].bits & format) { snprintf(end, size,"%s|",AST_FORMAT_LIST[x].name); len = strlen(end); @@ -561,7 +561,7 @@ static const char *ast_expand_codec_alias(const char *in) { int x; - for (x = 0; x < sizeof(ast_codec_alias_table) / sizeof(ast_codec_alias_table[0]); x++) { + for (x = 0; x < ARRAY_LEN(ast_codec_alias_table); x++) { if (!strcmp(in,ast_codec_alias_table[x].alias)) return ast_codec_alias_table[x].realname; } @@ -573,7 +573,7 @@ int ast_getformatbyname(const char *name) int x, all, format = 0; all = strcasecmp(name, "all") ? 0 : 1; - for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { + for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) { if (all || !strcasecmp(AST_FORMAT_LIST[x].name,name) || !strcasecmp(AST_FORMAT_LIST[x].name, ast_expand_codec_alias(name))) { @@ -590,7 +590,7 @@ char *ast_codec2str(int codec) { int x; char *ret = "unknown"; - for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { + for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) { if (AST_FORMAT_LIST[x].bits == codec) { ret = AST_FORMAT_LIST[x].desc; break; @@ -1023,7 +1023,7 @@ void ast_codec_pref_remove(struct ast_codec_pref *pref, int format) memcpy(&oldorder, pref, sizeof(oldorder)); memset(pref, 0, sizeof(*pref)); - for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { + for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) { slot = oldorder.order[x]; size = oldorder.framing[x]; if (! slot) @@ -1043,7 +1043,7 @@ int ast_codec_pref_append(struct ast_codec_pref *pref, int format) ast_codec_pref_remove(pref, format); - for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { + for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) { if (AST_FORMAT_LIST[x].bits == format) { newindex = x + 1; break; @@ -1051,7 +1051,7 @@ int ast_codec_pref_append(struct ast_codec_pref *pref, int format) } if (newindex) { - for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { + for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) { if (!pref->order[x]) { pref->order[x] = newindex; break; @@ -1104,7 +1104,7 @@ int ast_codec_pref_setsize(struct ast_codec_pref *pref, int format, int framems) { int x, index = -1; - for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { + for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) { if (AST_FORMAT_LIST[x].bits == format) { index = x; break; @@ -1128,7 +1128,7 @@ int ast_codec_pref_setsize(struct ast_codec_pref *pref, int format, int framems) framems = AST_FORMAT_LIST[index].max_ms; - for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { + for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) { if (pref->order[x] == (index + 1)) { pref->framing[x] = framems; break; @@ -1144,7 +1144,7 @@ struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, int f int x, index = -1, framems = 0; struct ast_format_list fmt = { 0, }; - for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { + for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) { if (AST_FORMAT_LIST[x].bits == format) { fmt = AST_FORMAT_LIST[x]; index = x; @@ -1152,7 +1152,7 @@ struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, int f } } - for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { + for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) { if (pref->order[x] == (index + 1)) { framems = pref->framing[x]; break; @@ -1182,7 +1182,7 @@ int ast_codec_choose(struct ast_codec_pref *pref, int formats, int find_best) { int x, ret = 0, slot; - for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) { + for (x = 0; x < ARRAY_LEN(AST_FORMAT_LIST); x++) { slot = pref->order[x]; if (!slot) diff --git a/main/logger.c b/main/logger.c index 47c7772f0..18a864c0d 100644 --- a/main/logger.c +++ b/main/logger.c @@ -530,7 +530,7 @@ static int rotate_file(const char *filename) /* Find the next empty slot, including a possible suffix */ for (x = 0; ; x++) { found = 0; - for (which = 0; which < sizeof(suffixes) / sizeof(suffixes[0]); which++) { + for (which = 0; which < ARRAY_LEN(suffixes); which++) { snprintf(new, sizeof(new), "%s.%d%s", filename, x, suffixes[which]); fd = open(new, O_RDONLY); if (fd > -1) @@ -546,7 +546,7 @@ static int rotate_file(const char *filename) /* Found an empty slot */ for (y = x; y > -1; y--) { - for (which = 0; which < sizeof(suffixes) / sizeof(suffixes[0]); which++) { + for (which = 0; which < ARRAY_LEN(suffixes); which++) { snprintf(old, sizeof(old), "%s.%d%s", filename, y - 1, suffixes[which]); fd = open(old, O_RDONLY); if (fd > -1) { diff --git a/main/manager.c b/main/manager.c index 679a8899e..486953fb5 100644 --- a/main/manager.c +++ b/main/manager.c @@ -345,7 +345,7 @@ static char *authority_to_str(int authority, struct ast_str **res) char *sep = ""; (*res)->used = 0; - for (i = 0; i < (sizeof(perms) / sizeof(perms[0])) - 1; i++) { + for (i = 0; i < ARRAY_LEN(perms) - 1; i++) { if (authority & perms[i].num) { ast_str_append(res, 0, "%s%s", sep, perms[i].label); sep = ","; @@ -387,7 +387,7 @@ static int get_perm(const char *instr) if (!instr) return 0; - for (x = 0; x < (sizeof(perms) / sizeof(perms[0])); x++) { + for (x = 0; x < ARRAY_LEN(perms); x++) { if (ast_instring(instr, perms[x].label, ',')) ret |= perms[x].num; } @@ -415,7 +415,7 @@ static int strings_to_mask(const char *string) return 0; if (ast_true(string)) { /* all permissions */ int x, ret = 0; - for (x = 0; x<sizeof(perms) / sizeof(perms[0]); x++) + for (x = 0; x < ARRAY_LEN(perms); x++) ret |= perms[x].num; return ret; } diff --git a/main/pbx.c b/main/pbx.c index d0ae17e9b..544c703f2 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -2320,7 +2320,7 @@ void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, c } } /* if not found, look into chanvars or global vars */ - for (i = 0; s == ¬_found && i < (sizeof(places) / sizeof(places[0])); i++) { + for (i = 0; s == ¬_found && i < ARRAY_LEN(places); i++) { struct ast_var_t *variables; if (!places[i]) continue; @@ -3098,7 +3098,7 @@ const char *ast_extension_state2str(int extension_state) { int i; - for (i = 0; (i < (sizeof(extension_states) / sizeof(extension_states[0]))); i++) { + for (i = 0; (i < ARRAY_LEN(extension_states)); i++) { if (extension_states[i].extension_state == extension_state) return extension_states[i].text; } diff --git a/main/rtp.c b/main/rtp.c index c0c2bf17f..1370e12d2 100644 --- a/main/rtp.c +++ b/main/rtp.c @@ -2205,7 +2205,7 @@ int ast_rtp_set_rtpmap_type(struct ast_rtp *rtp, int pt, rtp_bridge_lock(rtp); - for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) { + for (i = 0; i < ARRAY_LEN(mimeTypes); ++i) { if (strcasecmp(mimeSubtype, mimeTypes[i].subtype) == 0 && strcasecmp(mimeType, mimeTypes[i].type) == 0) { found = 1; @@ -2312,7 +2312,7 @@ const char *ast_rtp_lookup_mime_subtype(const int isAstFormat, const int code, { unsigned int i; - for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) { + for (i = 0; i < ARRAY_LEN(mimeTypes); ++i) { if ((mimeTypes[i].payloadType.code == code) && (mimeTypes[i].payloadType.isAstFormat == isAstFormat)) { if (isAstFormat && (code == AST_FORMAT_G726_AAL2) && |