]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tidy-up: use `CURL_ARRAYSIZE()`
authorViktor Szakats <commit@vsz.me>
Tue, 18 Feb 2025 13:48:18 +0000 (14:48 +0100)
committerViktor Szakats <commit@vsz.me>
Tue, 18 Feb 2025 23:59:45 +0000 (00:59 +0100)
Follow-up to 13b2ea68f0e08b2746669addfbc7b0ecd5f1bf0e #16111

Closes #16381

35 files changed:
lib/cf-h2-proxy.c
lib/http.c
lib/http2.c
lib/mime.c
lib/openldap.c
lib/parsedate.c
lib/strerror.c
lib/vquic/curl_ngtcp2.c
lib/vssh/libssh2.c
lib/vssh/wolfssh.c
lib/vtls/bearssl.c
lib/vtls/cipher_suite.c
lib/vtls/sectransp.c
lib/ws.c
src/tool_cb_wrt.c
src/tool_getparam.c
src/tool_libinfo.c
src/tool_paramhlp.c
src/tool_writeout.c
tests/libtest/first.c
tests/libtest/lib1156.c
tests/libtest/lib578.c
tests/unit/unit1303.c
tests/unit/unit1307.c
tests/unit/unit1323.c
tests/unit/unit1395.c
tests/unit/unit1604.c
tests/unit/unit1607.c
tests/unit/unit1609.c
tests/unit/unit1615.c
tests/unit/unit1650.c
tests/unit/unit1655.c
tests/unit/unit1657.c
tests/unit/unit2600.c
tests/unit/unit3205.c

index d8b91280c291d74ee2e53df28c02c7fc5302ac1d..ec7d4d53e61650b4d3ffc4a5b20715f56be268d1 100644 (file)
@@ -619,7 +619,7 @@ static int proxy_h2_fr_print(const nghttp2_frame *frame,
                        frame->hd.flags & NGHTTP2_FLAG_ACK);
     case NGHTTP2_GOAWAY: {
       char scratch[128];
-      size_t s_len = sizeof(scratch)/sizeof(scratch[0]);
+      size_t s_len = CURL_ARRAYSIZE(scratch);
       size_t len = (frame->goaway.opaque_data_len < s_len) ?
         frame->goaway.opaque_data_len : s_len-1;
       if(len)
index e054bf4b69e4b04e52d7e486fd123beb79a434f9..52bb368d5afd60c063e1d8eef7cb55190273c069 100644 (file)
@@ -4456,7 +4456,7 @@ static struct name_const H2_NON_FIELD[] = {
 static bool h2_non_field(const char *name, size_t namelen)
 {
   size_t i;
-  for(i = 0; i < sizeof(H2_NON_FIELD)/sizeof(H2_NON_FIELD[0]); ++i) {
+  for(i = 0; i < CURL_ARRAYSIZE(H2_NON_FIELD); ++i) {
     if(namelen < H2_NON_FIELD[i].namelen)
       return FALSE;
     if(namelen == H2_NON_FIELD[i].namelen &&
index b82b984935bd9c3fbfd825cf441eff495c9b8edf..1f36786aa25ebd96878e36db5ae7e00ac65acfbe 100644 (file)
@@ -1252,7 +1252,7 @@ static int fr_print(const nghttp2_frame *frame, char *buffer, size_t blen)
     }
     case NGHTTP2_GOAWAY: {
       char scratch[128];
-      size_t s_len = sizeof(scratch)/sizeof(scratch[0]);
+      size_t s_len = CURL_ARRAYSIZE(scratch);
       size_t len = (frame->goaway.opaque_data_len < s_len) ?
         frame->goaway.opaque_data_len : s_len-1;
       if(len)
index a90d170579d8925429ef937cc0782425cf688658..af5ef034fe7f1f2d3c8d8548a13a7ae4550ed7d4 100644 (file)
@@ -1742,7 +1742,7 @@ const char *Curl_mime_contenttype(const char *filename)
     const char *nameend = filename + len1;
     unsigned int i;
 
-    for(i = 0; i < sizeof(ctts) / sizeof(ctts[0]); i++) {
+    for(i = 0; i < CURL_ARRAYSIZE(ctts); i++) {
       size_t len2 = strlen(ctts[i].extension);
 
       if(len1 >= len2 && strcasecompare(nameend - len2, ctts[i].extension))
index 13f8abf191309adae0d6222413ec8f2b22c3c0a3..9475b33a89429d020b7631056e2fa3fc7e6cefa6 100644 (file)
@@ -277,7 +277,7 @@ static CURLcode oldap_url_parse(struct Curl_easy *data, LDAPURLDesc **ludp)
     result = rc == LDAP_URL_ERR_MEM ? CURLE_OUT_OF_MEMORY :
       CURLE_URL_MALFORMAT;
     rc -= LDAP_URL_SUCCESS;
-    if((size_t) rc < sizeof(url_errs) / sizeof(url_errs[0]))
+    if((size_t) rc < CURL_ARRAYSIZE(url_errs))
       msg = url_errs[rc];
     failf(data, "LDAP local: %s", msg);
   }
index 1795d6df6cdbd3056c00162b681ee2f426eb108a..132c0a8a2c3bd992c073b561a8137142b8d0116a 100644 (file)
@@ -256,7 +256,7 @@ static int checktz(const char *check, size_t len)
   if(len > 4) /* longer than any valid timezone */
     return -1;
 
-  for(i = 0; i < sizeof(tz)/sizeof(tz[0]); i++) {
+  for(i = 0; i < CURL_ARRAYSIZE(tz); i++) {
     size_t ilen = strlen(what->name);
     if((ilen == len) &&
        strncasecompare(check, what->name, len))
index 20495c9791a17a8784a7186ad3de85979fc1d813..f69c81663b69f27405596b75770ad0607ab52d48 100644 (file)
@@ -791,7 +791,7 @@ get_winapi_error(int err, char *buf, size_t buflen)
      FormatMessageW -> wcstombs is used for Windows CE compatibility. */
   if(FormatMessageW((FORMAT_MESSAGE_FROM_SYSTEM |
                      FORMAT_MESSAGE_IGNORE_INSERTS), NULL, (DWORD)err,
-                    LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL)) {
+                    LANG_NEUTRAL, wbuf, CURL_ARRAYSIZE(wbuf), NULL)) {
     size_t written = wcstombs(buf, wbuf, buflen - 1);
     if(written != (size_t)-1)
       buf[written] = '\0';
index cc9d560d7023ec177014effb698ed5e13dde6c24..92c39b5a03388a0a800875835baa98544895b0c3 100644 (file)
@@ -1759,7 +1759,7 @@ static ssize_t read_pkt_to_send(void *userp,
 
     if(ctx->h3conn && ngtcp2_conn_get_max_data_left(ctx->qconn)) {
       veccnt = nghttp3_conn_writev_stream(ctx->h3conn, &stream_id, &fin, vec,
-                                          sizeof(vec) / sizeof(vec[0]));
+                                          CURL_ARRAYSIZE(vec));
       if(veccnt < 0) {
         failf(x->data, "nghttp3_conn_writev_stream returned error: %s",
               nghttp3_strerror((int)veccnt));
index a32483955ce78056f0ccc6ea59f7e129ac02c55d..17e9a3e5530d09c452e9e8dc484918e837e53e67 100644 (file)
@@ -369,7 +369,7 @@ static void state(struct Curl_easy *data, sshstate nowstate)
   };
 
   /* a precaution to make sure the lists are in sync */
-  DEBUGASSERT(sizeof(names)/sizeof(names[0]) == SSH_LAST);
+  DEBUGASSERT(CURL_ARRAYSIZE(names) == SSH_LAST);
 
   if(sshc->state != nowstate) {
     infof(data, "SFTP %p state change from %s to %s",
index 4c6a609f48d2b409f067e01efb9bd60a77ff1e4b..4cd955c892594843968a72fd2a28864e02de52fe 100644 (file)
@@ -207,7 +207,7 @@ static void state(struct Curl_easy *data, sshstate nowstate)
   };
 
   /* a precaution to make sure the lists are in sync */
-  DEBUGASSERT(sizeof(names)/sizeof(names[0]) == SSH_LAST);
+  DEBUGASSERT(CURL_ARRAYSIZE(names) == SSH_LAST);
 
   if(sshc->state != nowstate) {
     infof(data, "wolfssh %p state change from %s to %s",
index c52f28d748c171dc51d166b5d2c5bd5cea832090..8b15b03d2d79f215e8517389a1bcbc3101223941 100644 (file)
@@ -484,7 +484,7 @@ static const uint16_t ciphertable[] = {
   BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,        /* 0xCCA9 */
 };
 
-#define NUM_OF_CIPHERS (sizeof(ciphertable) / sizeof(ciphertable[0]))
+#define NUM_OF_CIPHERS CURL_ARRAYSIZE(ciphertable)
 
 static CURLcode bearssl_set_selected_ciphers(struct Curl_easy *data,
                                              br_ssl_engine_context *ssl_eng,
index a694b14627935d69884595c678e10d2699737d62..89adb945f60866bc3b96676b35426827c75b995c 100644 (file)
@@ -725,7 +725,7 @@ static const struct cs_entry cs_list [] = {
   CS_ENTRY(0xCCAE, RSA,PSK,CHACHA20,POLY1305,,,,),
 #endif
 };
-#define CS_LIST_LEN (sizeof(cs_list) / sizeof(cs_list[0]))
+#define CS_LIST_LEN CURL_ARRAYSIZE(cs_list)
 
 static int cs_str_to_zip(const char *cs_str, size_t cs_len,
                          uint8_t zip[6])
index 2e72a50296b92196ce26cd8887c70c3960467567..bd8bf282fe04e726bdc83c05545abbe819856a05 100644 (file)
@@ -211,9 +211,6 @@ static const uint16_t default_ciphers[] = {
 #endif /* CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11 */
 };
 
-#define DEFAULT_CIPHERS_LEN sizeof(default_ciphers)/sizeof(default_ciphers[0])
-
-
 /* pinned public key support tests */
 
 /* version 1 supports macOS 10.12+ and iOS 10+ */
@@ -925,7 +922,7 @@ static CURLcode sectransp_set_default_ciphers(struct Curl_easy *data,
   /* Intersect the ciphers supported by Secure Transport with the default
    * ciphers, using the order of the former. */
   for(i = 0; i < supported_len; i++) {
-    for(j = 0; j < DEFAULT_CIPHERS_LEN; j++) {
+    for(j = 0; j < CURL_ARRAYSIZE(default_ciphers); j++) {
       if(default_ciphers[j] == ciphers[i]) {
         ciphers[count++] = ciphers[i];
         break;
index 23ee016229ea50cf1900c3238cf0add3754d03ea..9510622683ac72d6ce83f70f24c6da586dc090e3 100644 (file)
--- a/lib/ws.c
+++ b/lib/ws.c
@@ -85,7 +85,7 @@ static const char *ws_frame_name_of_op(unsigned char proto_opcode)
 {
   unsigned char opcode = proto_opcode & WSBIT_OPCODE_MASK;
   size_t i;
-  for(i = 0; i < sizeof(WS_FRAMES)/sizeof(WS_FRAMES[0]); ++i) {
+  for(i = 0; i < CURL_ARRAYSIZE(WS_FRAMES); ++i) {
     if(WS_FRAMES[i].proto_opcode == opcode)
       return WS_FRAMES[i].name;
   }
@@ -96,7 +96,7 @@ static int ws_frame_op2flags(unsigned char proto_opcode)
 {
   unsigned char opcode = proto_opcode & WSBIT_OPCODE_MASK;
   size_t i;
-  for(i = 0; i < sizeof(WS_FRAMES)/sizeof(WS_FRAMES[0]); ++i) {
+  for(i = 0; i < CURL_ARRAYSIZE(WS_FRAMES); ++i) {
     if(WS_FRAMES[i].proto_opcode == opcode)
       return WS_FRAMES[i].flags;
   }
@@ -106,7 +106,7 @@ static int ws_frame_op2flags(unsigned char proto_opcode)
 static unsigned char ws_frame_flags2op(int flags)
 {
   size_t i;
-  for(i = 0; i < sizeof(WS_FRAMES)/sizeof(WS_FRAMES[0]); ++i) {
+  for(i = 0; i < CURL_ARRAYSIZE(WS_FRAMES); ++i) {
     if(WS_FRAMES[i].flags & flags)
       return (unsigned char)WS_FRAMES[i].proto_opcode;
   }
@@ -747,7 +747,7 @@ CURLcode Curl_ws_request(struct Curl_easy *data, struct dynbuf *req)
   }
   strcpy(keyval, randstr);
   free(randstr);
-  for(i = 0; !result && (i < sizeof(heads)/sizeof(heads[0])); i++) {
+  for(i = 0; !result && (i < CURL_ARRAYSIZE(heads)); i++) {
     if(!Curl_checkheaders(data, STRCONST(heads[i].name))) {
       result = Curl_dyn_addf(req, "%s %s\r\n", heads[i].name,
                              heads[i].val);
index f5293094e1548d74d645e400562d08c8d4e98128..5d6ef1735d42ca93f5990600cfc0d78b5975fba5 100644 (file)
@@ -265,7 +265,7 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
         WCHAR prefix[3] = {0};  /* UTF-16 (1-2 WCHARs) + NUL */
 
         if(MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)outs->utf8seq, -1,
-                               prefix, sizeof(prefix)/sizeof(prefix[0]))) {
+                               prefix, CURL_ARRAYSIZE(prefix))) {
           DEBUGASSERT(prefix[2] == L'\0');
           if(!WriteConsoleW(
               (HANDLE) fhnd,
index 40ac4e3417004766f61d75d0f46c044bee5c0a72..f66124d40a277e120677e0c6780817984bfd5779 100644 (file)
@@ -754,7 +754,7 @@ const struct LongShort *findshortopt(char letter)
 
   if(!singles_done) {
     unsigned int j;
-    for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
+    for(j = 0; j < CURL_ARRAYSIZE(aliases); j++) {
       if(aliases[j].letter != ' ') {
         unsigned char l = (unsigned char)aliases[j].letter;
         singles[l - ' '] = &aliases[j];
@@ -1016,7 +1016,7 @@ const struct LongShort *findlongopt(const char *opt)
   struct LongShort key;
   key.lname = opt;
 
-  return bsearch(&key, aliases, sizeof(aliases)/sizeof(aliases[0]),
+  return bsearch(&key, aliases, CURL_ARRAYSIZE(aliases),
                  sizeof(aliases[0]), findarg);
 }
 
@@ -1961,7 +1961,7 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
       const struct TOSEntry *entry;
       find.name = nextarg;
       entry = bsearch(&find, tos_entries,
-                      sizeof(tos_entries)/sizeof(*tos_entries),
+                      CURL_ARRAYSIZE(tos_entries),
                       sizeof(*tos_entries), find_tos);
       if(entry)
         config->ip_tos = entry->value;
index 9da5075b9258a11b59f4ab35f86c98779431cf02..0563c4c5926ebedb91949ef70fb52599fec8f0b0 100644 (file)
@@ -127,7 +127,7 @@ static struct feature_name_presentp {
   {NULL,             NULL,                0}
 };
 
-static const char *fnames[sizeof(maybe_feature) / sizeof(maybe_feature[0])];
+static const char *fnames[CURL_ARRAYSIZE(maybe_feature)];
 const char * const *feature_names = fnames;
 size_t feature_count;
 
index 5abf49d342691425620da512e64078b93ed5cbb1..fc6da854548ac29edf8ec63558ff6de4731cf51a 100644 (file)
@@ -793,7 +793,7 @@ ParameterError str2tls_max(long *val, const char *str)
   size_t i = 0;
   if(!str)
     return PARAM_REQUIRES_PARAMETER;
-  for(i = 0; i < sizeof(tls_max_array)/sizeof(tls_max_array[0]); i++) {
+  for(i = 0; i < CURL_ARRAYSIZE(tls_max_array); i++) {
     if(!strcmp(str, tls_max_array[i].tls_max_str)) {
       *val = tls_max_array[i].tls_max;
       return PARAM_OK;
index 6c92c9aaf10868ffd6f8b78042ca65d4c9fc5ec1..a05d212842ffeac90f56f5111bc9be10f48e54b3 100644 (file)
@@ -577,7 +577,7 @@ void ourWriteOut(struct OperationConfig *config, struct per_transfer *per,
           if(!curlx_dyn_addn(&name, ptr, vlen)) {
             find.name = curlx_dyn_ptr(&name);
             wv = bsearch(&find,
-                         variables, sizeof(variables)/sizeof(variables[0]),
+                         variables, CURL_ARRAYSIZE(variables),
                          sizeof(variables[0]), matchvar);
           }
           if(wv) {
@@ -601,7 +601,7 @@ void ourWriteOut(struct OperationConfig *config, struct per_transfer *per,
               break;
             case VAR_JSON:
               ourWriteOutJSON(stream, variables,
-                              sizeof(variables)/sizeof(variables[0]),
+                              CURL_ARRAYSIZE(variables),
                               per, per_result);
               break;
             case VAR_HEADER_JSON:
index 937c66c4db510b4373fd9b6ee4c9121dc229a387..e098a744f13dacc53b082b997738aff4e96669eb 100644 (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;
index 6854e3bc445265b6200e12b4fe568cd1c0909dec..90893dabcb258f301ead866b52fed90c5b89d7f6 100644 (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");
index 6be64a1aa1df2902baa0809c2179f03987cfa7e0..af42e206b8b2566cab05fa278267ea4bc6c23e11 100644 (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)
index 93262706b3a5ddabbe9b008ba68422e44ae8e58d..95f0630560ff5759a6fc30ffa00f54d89fbc547a 100644 (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);
index 08faa339033142384ee95480a9ed206ea4be2668..7237cf5421fa87aea994dc858165545bb9d8b422 100644 (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)) {
index bdd02b5de5d01e2a1987a03595ab4bd643973c47..46c3eb0e0002f160ca8bc08595a9e4ddb6d27122 100644 (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",
index 017b45a0e40abc1e1c4a2b99a8d912519610e5fe..dd1f29a307e3ece0008288439b468363f80b513a 100644 (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");
index 690779202377cd64f5177d4ffa2fc3c9915b5689..f2b727b62936d9fe4ab130e034b643d6dfa07fc3 100644 (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;
index ecc1fc931e5fa4e34632c5bbcfe8ee602cf999ac..5b658eb02d05078a9579c93ecedebb576fefeaa7 100644 (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;
index c902243f5953087c42aea9efebf8bfe42c5901d0..04b53b0d7239e811a57e650e55c2be1e01836c51 100644 (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;
index 72b751c3bd39be745d86c56990b5e445f3d1cc73..b0b32b61fcb7bb525ee136ffef4e22aecfa43224 100644 (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 */
index 6d6261e1cc72baa6d2897bf5f2f1592c145d546d..51e4b48fe9ac1330a1ea4285f56aeed502ebce10 100644 (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;
index 6c9298de3065cfa51e37e79a766e84f16e11a001..384fc120e6e736a37787434614998b5ac9bca49d 100644 (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;
index bd973fdbb4efb461a166f6c9753a5be0aced2bf4..d5062cda77e1e5a1f368ec8cb0259e3c124b400c 100644 (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;
   }
index 352cdefbf2e97146290d50563ed69c4f56408ae1..8c19ebc774a6741ef854072a6d3da2e7b35bb8af 100644 (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]);
   }
 
index 4a2423e6bf54ff8d4a9d4c1d84b231c987729e1a..825b8000e477fa804213bac3904ee214fa260880 100644 (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;