Use PJ_ARRAY_SIZE() replace sizeof()/sizeof() (#3439)
This commit is contained in:
parent
dfe315ac5f
commit
8c41a770fe
|
@ -126,7 +126,7 @@ static int xml_parse_print_test(const char *doc)
|
|||
int xml_test()
|
||||
{
|
||||
unsigned i;
|
||||
for (i=0; i<sizeof(xml_doc)/sizeof(xml_doc[0]); ++i) {
|
||||
for (i=0; i<PJ_ARRAY_SIZE(xml_doc); ++i) {
|
||||
int status;
|
||||
if ((status=xml_parse_print_test(xml_doc[i])) != 0)
|
||||
return status;
|
||||
|
|
|
@ -389,7 +389,7 @@ PJ_DEF(pj_status_t) pj_cli_create(pj_cli_cfg *cfg,
|
|||
pj_list_init(cli->root.sub_cmd);
|
||||
|
||||
/* Register some standard commands. */
|
||||
for (i = 0; i < sizeof(cmd_xmls)/sizeof(cmd_xmls[0]); i++) {
|
||||
for (i = 0; i < PJ_ARRAY_SIZE(cmd_xmls); i++) {
|
||||
pj_str_t xml = pj_str(cmd_xmls[i]);
|
||||
|
||||
if (pj_cli_add_cmd_from_xml(cli, NULL, &xml,
|
||||
|
|
|
@ -95,7 +95,7 @@ static int pjlib_error(pj_status_t code, char *buf, pj_size_t size)
|
|||
#if defined(PJ_HAS_ERROR_STRING) && PJ_HAS_ERROR_STRING!=0
|
||||
unsigned i;
|
||||
|
||||
for (i=0; i<sizeof(err_str)/sizeof(err_str[0]); ++i) {
|
||||
for (i=0; i<PJ_ARRAY_SIZE(err_str); ++i) {
|
||||
if (err_str[i].code == code) {
|
||||
pj_size_t len2 = pj_ansi_strlen(err_str[i].msg);
|
||||
if (len2 >= size) len2 = size-1;
|
||||
|
|
|
@ -1766,8 +1766,8 @@ static void ssl_ciphers_populate(void)
|
|||
};
|
||||
if (!ssl_cipher_num) {
|
||||
unsigned i;
|
||||
|
||||
ssl_cipher_num = sizeof(ciphers)/sizeof(ciphers[0]);
|
||||
|
||||
ssl_cipher_num = PJ_ARRAY_SIZE(ciphers);
|
||||
for (i = 0; i < ssl_cipher_num; i++) {
|
||||
ssl_ciphers[i].id = (pj_ssl_cipher)ciphers[i];
|
||||
ssl_ciphers[i].name = sslGetCipherSuiteString(ciphers[i]);
|
||||
|
|
|
@ -549,7 +549,7 @@ static int ioqueue_perf_test_imp(const pj_ioqueue_cfg *cfg)
|
|||
PJ_LOG(3,(THIS_FILE, " ======================================="));
|
||||
|
||||
best_bandwidth = 0;
|
||||
for (i=0; i<(int)(sizeof(test_param)/sizeof(test_param[0])); ++i) {
|
||||
for (i=0; i<(int)PJ_ARRAY_SIZE(test_param); ++i) {
|
||||
pj_size_t bandwidth;
|
||||
|
||||
rc = perform_test(cfg,
|
||||
|
|
|
@ -444,8 +444,7 @@ static int simple_sock_test(void)
|
|||
|
||||
PJ_LOG(3,("test", "...simple_sock_test()"));
|
||||
|
||||
for (i=0; i<(int)(sizeof(types)/sizeof(types[0])); ++i) {
|
||||
|
||||
for (i=0; i<(int)PJ_ARRAY_SIZE(types); ++i) {
|
||||
rc = pj_sock_socket(pj_AF_INET(), types[i], 0, &sock);
|
||||
if (rc != PJ_SUCCESS) {
|
||||
app_perror("...error: unable to create socket", rc);
|
||||
|
|
|
@ -307,8 +307,7 @@ PJ_DEF(pj_status_t) pjmedia_codec_silk_set_config(
|
|||
unsigned i;
|
||||
|
||||
/* Look up in factory modes table */
|
||||
for (i = 0; i < sizeof(silk_factory.silk_param)/
|
||||
sizeof(silk_factory.silk_param[0]); ++i)
|
||||
for (i = 0; i < PJ_ARRAY_SIZE(silk_factory.silk_param); ++i)
|
||||
{
|
||||
if (silk_factory.silk_param[i].clock_rate == clock_rate) {
|
||||
int quality = PJMEDIA_CODEC_SILK_DEFAULT_QUALITY;
|
||||
|
|
|
@ -210,7 +210,7 @@ static pj_status_t cbar_factory_init(pjmedia_vid_dev_factory *f)
|
|||
ddi->info.has_callback = PJ_FALSE;
|
||||
|
||||
ddi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT;
|
||||
ddi->info.fmt_cnt = sizeof(cbar_fmts)/sizeof(cbar_fmts[0]);
|
||||
ddi->info.fmt_cnt = PJ_ARRAY_SIZE(cbar_fmts);
|
||||
for (i = 0; i < ddi->info.fmt_cnt; i++) {
|
||||
pjmedia_format *fmt = &ddi->info.fmt[i];
|
||||
pjmedia_format_init_video(fmt, cbar_fmts[i].fmt_id,
|
||||
|
@ -230,7 +230,7 @@ static pj_status_t cbar_factory_init(pjmedia_vid_dev_factory *f)
|
|||
ddi->info.has_callback = PJ_TRUE;
|
||||
|
||||
ddi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT;
|
||||
ddi->info.fmt_cnt = sizeof(cbar_fmts)/sizeof(cbar_fmts[0]);
|
||||
ddi->info.fmt_cnt = PJ_ARRAY_SIZE(cbar_fmts);
|
||||
for (i = 0; i < ddi->info.fmt_cnt; i++) {
|
||||
pjmedia_format *fmt = &ddi->info.fmt[i];
|
||||
pjmedia_format_init_video(fmt, cbar_fmts[i].fmt_id,
|
||||
|
@ -313,7 +313,7 @@ static const struct cbar_fmt_info* get_cbar_fmt_info(pjmedia_format_id id)
|
|||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < sizeof(cbar_fmts)/sizeof(cbar_fmts[0]); i++) {
|
||||
for (i = 0; i < PJ_ARRAY_SIZE(cbar_fmts); i++) {
|
||||
if (cbar_fmts[i].fmt_id == id)
|
||||
return &cbar_fmts[i];
|
||||
}
|
||||
|
|
|
@ -328,11 +328,10 @@ static void enum_dev_cap(IBaseFilter *filter,
|
|||
if (FAILED (hr))
|
||||
continue;
|
||||
|
||||
nformat = (dshow_fmt? 1:
|
||||
sizeof(dshow_fmts)/sizeof(dshow_fmts[0]));
|
||||
nformat = (dshow_fmt ? 1 : PJ_ARRAY_SIZE(dshow_fmts));
|
||||
for (j = 0; j < nformat; j++) {
|
||||
const GUID *dshow_format = dshow_fmt;
|
||||
|
||||
|
||||
if (!dshow_format)
|
||||
dshow_format = dshow_fmts[j].dshow_format;
|
||||
if (UuidCompare(&mediatype->subtype,
|
||||
|
@ -414,7 +413,7 @@ static pj_status_t dshow_factory_refresh(pjmedia_vid_dev_factory *f)
|
|||
df->dev_pool = NULL;
|
||||
}
|
||||
|
||||
for (c = 0; c < sizeof(dshow_fmts) / sizeof(dshow_fmts[0]); c++) {
|
||||
for (c = 0; c < PJ_ARRAY_SIZE(dshow_fmts); c++) {
|
||||
dshow_fmts[c].enabled = PJ_FALSE;
|
||||
}
|
||||
|
||||
|
@ -670,7 +669,7 @@ static dshow_fmt_info* get_dshow_format_info(pjmedia_format_id id)
|
|||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < sizeof(dshow_fmts)/sizeof(dshow_fmts[0]); i++) {
|
||||
for (i = 0; i < PJ_ARRAY_SIZE(dshow_fmts); i++) {
|
||||
if (dshow_fmts[i].pjmedia_format == id && dshow_fmts[i].enabled)
|
||||
return &dshow_fmts[i];
|
||||
}
|
||||
|
|
|
@ -632,7 +632,7 @@ static sdl_fmt_info* get_sdl_format_info(pjmedia_format_id id)
|
|||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < sizeof(sdl_fmts)/sizeof(sdl_fmts[0]); i++) {
|
||||
for (i = 0; i < PJ_ARRAY_SIZE(sdl_fmts); i++) {
|
||||
if (sdl_fmts[i].fmt_id == id)
|
||||
return &sdl_fmts[i];
|
||||
}
|
||||
|
|
|
@ -305,13 +305,11 @@ pjmedia_avi_player_create_streams(pj_pool_t *pool,
|
|||
/* Normalize the endian */
|
||||
if (elem == sizeof(strf_video_hdr_t))
|
||||
data_to_host2(&avi_hdr.strf_hdr[i],
|
||||
sizeof(strf_video_hdr_sizes)/
|
||||
sizeof(strf_video_hdr_sizes[0]),
|
||||
PJ_ARRAY_SIZE(strf_video_hdr_sizes),
|
||||
strf_video_hdr_sizes);
|
||||
else if (elem == sizeof(strf_audio_hdr_t))
|
||||
data_to_host2(&avi_hdr.strf_hdr[i],
|
||||
sizeof(strf_audio_hdr_sizes)/
|
||||
sizeof(strf_audio_hdr_sizes[0]),
|
||||
PJ_ARRAY_SIZE(strf_audio_hdr_sizes),
|
||||
strf_audio_hdr_sizes);
|
||||
|
||||
/* Skip the remainder of the header */
|
||||
|
@ -395,7 +393,7 @@ pjmedia_avi_player_create_streams(pj_pool_t *pool,
|
|||
}
|
||||
|
||||
fmt_id = avi_hdr.strl_hdr[i].codec;
|
||||
for (j = sizeof(avi_fmts)/sizeof(avi_fmts[0])-1; j >= 0; j--) {
|
||||
for (j = (int)PJ_ARRAY_SIZE(avi_fmts)-1; j >= 0; j--) {
|
||||
/* Check supported video formats here */
|
||||
if (fmt_id == avi_fmts[j].fmt_id) {
|
||||
if (avi_fmts[j].eff_fmt_id)
|
||||
|
|
|
@ -588,7 +588,7 @@ static void pjmedia_srtp_deinit_lib(pjmedia_endpt *endpt)
|
|||
static int get_crypto_idx(const pj_str_t* crypto_name)
|
||||
{
|
||||
int i;
|
||||
int cs_cnt = sizeof(crypto_suites)/sizeof(crypto_suites[0]);
|
||||
int cs_cnt = PJ_ARRAY_SIZE(crypto_suites);
|
||||
|
||||
/* treat unspecified crypto_name as crypto 'NULL' */
|
||||
if (crypto_name->slen == 0)
|
||||
|
@ -645,7 +645,7 @@ PJ_DEF(pj_status_t) pjmedia_srtp_enum_crypto(unsigned *count,
|
|||
|
||||
PJ_ASSERT_RETURN(count && crypto, PJ_EINVAL);
|
||||
|
||||
max = sizeof(crypto_suites) / sizeof(crypto_suites[0]) - 1;
|
||||
max = PJ_ARRAY_SIZE(crypto_suites) - 1;
|
||||
if (*count > max)
|
||||
*count = max;
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ static int sdp_conform_test(pj_pool_factory *pf)
|
|||
int i, len;
|
||||
char buf[1500];
|
||||
|
||||
for (i=0; i<sizeof(sdp)/sizeof(sdp[0]); ++i) {
|
||||
for (i=0; i<PJ_ARRAY_SIZE(sdp); ++i) {
|
||||
pool = pj_pool_create(pf, "sdp", 4096, 0, NULL);
|
||||
ses = pjsdp_parse(sdp[i], strlen(sdp[i]), pool);
|
||||
len = pjsdp_print(ses, buf, sizeof(buf));
|
||||
|
|
|
@ -241,9 +241,9 @@ static int aviplay(pj_pool_t *pool, const char *fname)
|
|||
pjmedia_port codec_port;
|
||||
pjmedia_vid_codec_param codec_param;
|
||||
struct codec_fmt *codecp = NULL;
|
||||
|
||||
|
||||
/* Lookup codec */
|
||||
for (i = 0; i < sizeof(codec_fmts)/sizeof(codec_fmts[0]); i++) {
|
||||
for (i = 0; i < PJ_ARRAY_SIZE(codec_fmts); i++) {
|
||||
if (vid_port->info.fmt.id == codec_fmts[i].pjmedia_id) {
|
||||
codecp = &codec_fmts[i];
|
||||
break;
|
||||
|
|
|
@ -641,8 +641,7 @@ PJ_DEF(const pj_str_t*) pjsip_get_status_text(int code)
|
|||
init_status_phrase();
|
||||
}
|
||||
|
||||
return (code>=100 &&
|
||||
code<(int)(sizeof(status_phrase)/sizeof(status_phrase[0]))) ?
|
||||
return (code>=100 && code<(int)PJ_ARRAY_SIZE(status_phrase)) ?
|
||||
&status_phrase[code] : &status_phrase[0];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue