tidy-up: use CURL_ARRAYSIZE()

Follow-up to 13b2ea68f0 #16111

Closes #16381
This commit is contained in:
Viktor Szakats 2025-02-18 14:48:18 +01:00
parent 1b710381ca
commit 3fd1dfc829
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
35 changed files with 52 additions and 64 deletions

View file

@ -169,7 +169,7 @@ int main(int argc, char **argv)
test_func = NULL;
{
size_t tmp;
for(tmp = 0; tmp < (sizeof(s_tests)/sizeof((s_tests)[0])); ++tmp) {
for(tmp = 0; tmp < CURL_ARRAYSIZE(s_tests); ++tmp) {
if(strcmp(test_name, s_tests[tmp].name) == 0) {
test_func = s_tests[tmp].ptr;
break;

View file

@ -143,7 +143,7 @@ CURLcode test(char *URL)
return TEST_ERR_MAJOR_BAD;
}
for(i = 0; i < sizeof(testparams) / sizeof(testparams[0]); i++) {
for(i = 0; i < CURL_ARRAYSIZE(testparams); i++) {
curl = curl_easy_init();
if(!curl) {
fprintf(stderr, "curl_easy_init() failed\n");

View file

@ -28,7 +28,7 @@
/* The size of data should be kept below MAX_INITIAL_POST_SIZE! */
static char testdata[]="this is a short string.\n";
static size_t data_size = sizeof(testdata) / sizeof(char);
static size_t data_size = CURL_ARRAYSIZE(testdata);
static int progress_callback(void *clientp, double dltotal, double dlnow,
double ultotal, double ulnow)

View file

@ -142,7 +142,7 @@ UNITTEST_START
testdata->progress.t_startop.tv_sec = BASE;
testdata->progress.t_startop.tv_usec = 0;
for(i = 0; i < sizeof(run)/sizeof(run[0]); i++) {
for(i = 0; i < CURL_ARRAYSIZE(run); i++) {
timediff_t timeout;
NOW(run[i].now_s, run[i].now_us);
TIMEOUTS(run[i].timeout_ms, run[i].connecttimeout_ms);

View file

@ -275,7 +275,6 @@ enum system {
UNITTEST_START
{
int testnum = sizeof(tests) / sizeof(struct testcase);
int i;
enum system machine;
@ -292,7 +291,7 @@ UNITTEST_START
machine = SYSTEM_CUSTOM;
#endif
for(i = 0; i < testnum; i++) {
for(i = 0; i < (int)CURL_ARRAYSIZE(tests); i++) {
int result = tests[i].result;
int rc = Curl_fnmatch(NULL, tests[i].pattern, tests[i].string);
if(result & (LINUX_DIFFER|MAC_DIFFER)) {

View file

@ -51,7 +51,7 @@ UNITTEST_START
};
size_t i;
for(i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
for(i = 0; i < CURL_ARRAYSIZE(tests); i++) {
timediff_t result = Curl_timediff(tests[i].first, tests[i].second);
if(result != tests[i].result) {
printf("%ld.%06u to %ld.%06u got %d, but expected %ld\n",

View file

@ -77,7 +77,7 @@ UNITTEST_START
{ "/.", "/" },
};
for(i = 0; i < sizeof(pairs)/sizeof(pairs[0]); i++) {
for(i = 0; i < CURL_ARRAYSIZE(pairs); i++) {
char *out;
int err = dedotdotify(pairs[i].input, strlen(pairs[i].input), &out);
abort_unless(err == 0, "returned error");

View file

@ -210,7 +210,7 @@ UNITTEST_START
size_t i;
for(i = 0; i < sizeof(data) / sizeof(data[0]); ++i) {
for(i = 0; i < CURL_ARRAYSIZE(data); ++i) {
char *output = NULL;
char *flagstr = NULL;
char *received_ccstr = NULL;

View file

@ -109,14 +109,13 @@ static const struct testcase tests[] = {
UNITTEST_START
{
int i;
int testnum = sizeof(tests) / sizeof(struct testcase);
struct Curl_multi *multi = NULL;
struct Curl_easy *easy = NULL;
struct curl_slist *list = NULL;
for(i = 0; i < testnum; ++i) {
for(i = 0; i < (int)CURL_ARRAYSIZE(tests); ++i) {
int j;
int addressnum = sizeof(tests[i].address) / sizeof(*tests[i].address);
int addressnum = CURL_ARRAYSIZE(tests[i].address);
struct Curl_addrinfo *addr;
struct Curl_dns_entry *dns;
void *entry_id;

View file

@ -101,7 +101,6 @@ static const struct testcase tests[] = {
UNITTEST_START
{
int i;
int testnum = sizeof(tests) / sizeof(struct testcase);
struct Curl_multi *multi = NULL;
struct Curl_easy *easy = NULL;
struct curl_slist *list = NULL;
@ -110,9 +109,9 @@ UNITTEST_START
and also clean cache after the loop. In contrast,for example,
test 1607 sets up and cleans cache on each iteration. */
for(i = 0; i < testnum; ++i) {
for(i = 0; i < (int)CURL_ARRAYSIZE(tests); ++i) {
int j;
int addressnum = sizeof (tests[i].address) / sizeof (*tests[i].address);
int addressnum = CURL_ARRAYSIZE(tests[i].address);
struct Curl_addrinfo *addr;
struct Curl_dns_entry *dns;
void *entry_id;

View file

@ -122,35 +122,35 @@ UNITTEST_START
computed_hash = output_buf;
Curl_sha512_256it(output_buf, (const unsigned char *) test_str1,
(sizeof(test_str1) / sizeof(char)) - 1);
CURL_ARRAYSIZE(test_str1) - 1);
verify_memory(computed_hash, precomp_hash1, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, (const unsigned char *) test_str2,
(sizeof(test_str2) / sizeof(char)) - 1);
CURL_ARRAYSIZE(test_str2) - 1);
verify_memory(computed_hash, precomp_hash2, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, (const unsigned char *) test_str3,
(sizeof(test_str3) / sizeof(char)) - 1);
CURL_ARRAYSIZE(test_str3) - 1);
verify_memory(computed_hash, precomp_hash3, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, (const unsigned char *) test_str4,
(sizeof(test_str4) / sizeof(char)) - 1);
CURL_ARRAYSIZE(test_str4) - 1);
verify_memory(computed_hash, precomp_hash4, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, (const unsigned char *) test_str5,
(sizeof(test_str5) / sizeof(char)) - 1);
CURL_ARRAYSIZE(test_str5) - 1);
verify_memory(computed_hash, precomp_hash5, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, (const unsigned char *) test_str6,
(sizeof(test_str6) / sizeof(char)) - 1);
CURL_ARRAYSIZE(test_str6) - 1);
verify_memory(computed_hash, precomp_hash6, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, (const unsigned char *) test_str7,
(sizeof(test_str7) / sizeof(char)) - 1);
CURL_ARRAYSIZE(test_str7) - 1);
verify_memory(computed_hash, precomp_hash7, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, test_seq8,
sizeof(test_seq8) / sizeof(unsigned char));
CURL_ARRAYSIZE(test_seq8));
verify_memory(computed_hash, precomp_hash8, CURL_SHA512_256_DIGEST_LENGTH);
#endif /* CURL_HAVE_SHA512_256 */

View file

@ -160,7 +160,7 @@ UNITTEST_START
size_t i;
unsigned char *p;
for(i = 0; i < sizeof(req) / sizeof(req[0]); i++) {
for(i = 0; i < CURL_ARRAYSIZE(req); i++) {
DOHcode rc = doh_req_encode(req[i].name, req[i].type,
buffer, sizeof(buffer), &size);
if(rc != req[i].rc) {
@ -183,7 +183,7 @@ UNITTEST_START
}
}
for(i = 0; i < sizeof(resp) / sizeof(resp[0]); i++) {
for(i = 0; i < CURL_ARRAYSIZE(resp); i++) {
struct dohentry d;
DOHcode rc;
char *ptr;

View file

@ -99,7 +99,7 @@ do {
{ max, DOH_OK } /* expect buffer overwrite */
};
for(i = 0; i < (int)(sizeof(playlist)/sizeof(*playlist)); i++) {
for(i = 0; i < (int)(CURL_ARRAYSIZE(playlist)); i++) {
const char *name = playlist[i].name;
size_t olen = 100000;
struct demo victim;

View file

@ -38,10 +38,6 @@ static void unit_stop(void)
#if defined(USE_GNUTLS) || defined(USE_SCHANNEL) || defined(USE_SECTRANSP) || \
defined(USE_MBEDTLS)
#ifndef ARRAYSIZE
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
#endif
struct test1657_spec {
CURLcode (*setbuf)(struct test1657_spec *spec, struct dynbuf *buf);
size_t n;
@ -112,7 +108,7 @@ UNITTEST_START
return TEST_ERR_MAJOR_BAD;
}
for(i = 0; i < ARRAYSIZE(test1657_specs); ++i) {
for(i = 0; i < CURL_ARRAYSIZE(test1657_specs); ++i) {
if(!do_test1657(&test1657_specs[i], i, &dbuf))
all_ok = FALSE;
}

View file

@ -397,7 +397,7 @@ UNITTEST_START
size_t i;
for(i = 0; i < sizeof(TEST_CASES)/sizeof(TEST_CASES[0]); ++i) {
for(i = 0; i < CURL_ARRAYSIZE(TEST_CASES); ++i) {
test_connect(&TEST_CASES[i]);
}

View file

@ -586,7 +586,6 @@ static const struct test_cs_entry test_cs_list[] = {
"RSA-PSK-CHACHA20-POLY1305" },
#endif
};
#define TEST_CS_LIST_LEN (sizeof(test_cs_list) / sizeof(test_cs_list[0]))
static const char *cs_test_string =
"TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:"
@ -685,11 +684,10 @@ static const struct test_str_entry test_str_list[] = {
{ 0x0000, "GIBBERISH" },
{ 0x0000, "" },
};
#define TEST_STR_LIST_LEN (sizeof(test_str_list) / sizeof(test_str_list[0]))
UNITTEST_START
{
for(size_t i = 0; i < TEST_CS_LIST_LEN; i++) {
for(size_t i = 0; i < CURL_ARRAYSIZE(test_cs_list); i++) {
const struct test_cs_entry *test = &test_cs_list[i];
const char *expect;
char buf[64] = "";
@ -762,7 +760,7 @@ UNITTEST_START
for(ptr = cs_test_string; ptr[0] != '\0'; ptr = end) {
const struct test_str_entry *test = &test_str_list[i];
abort_if(i == TEST_STR_LIST_LEN, "should have been done");
abort_if(i == CURL_ARRAYSIZE(test_str_list), "should have been done");
id = Curl_cipher_suite_walk_str(&ptr, &end);
len = end - ptr;