Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from curl:master #325

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cf-h2-proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion lib/http2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/mime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion lib/openldap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/parsedate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion lib/strerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion lib/vquic/curl_ngtcp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion lib/vssh/libssh2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion lib/vssh/wolfssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion lib/vtls/bearssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/vtls/cipher_suite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
5 changes: 1 addition & 4 deletions lib/vtls/sectransp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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+ */
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions lib/ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/tool_cb_wrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/tool_getparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/tool_libinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/tool_paramhlp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/tool_writeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/libtest/first.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/libtest/lib1156.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion tests/libtest/lib578.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/unit1303.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/unit1307.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ enum system {

UNITTEST_START
{
int testnum = sizeof(tests) / sizeof(struct testcase);
int i;
enum system machine;

Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/unit1323.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/unit1395.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/unit1604.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/unit1607.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/unit1609.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/unit1615.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Loading
Loading