diff --git a/CMake/CurlTests.c b/CMake/CurlTests.c index f43521bfd6..e8117410fd 100644 --- a/CMake/CurlTests.c +++ b/CMake/CurlTests.c @@ -65,7 +65,7 @@ int main(void) #include int main(void) { - const char *address = "localhost"; + static const char address[] = "localhost"; struct hostent h; int rc = 0; #if defined(HAVE_GETHOSTBYNAME_R_3) || \ diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index d0982e0d41..34572e438b 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -30,7 +30,7 @@ #include -static const char *urls[] = { +static const char * const urls[] = { "https://01.example/", "https://02.example/", "https://03.example/", diff --git a/docs/examples/crawler.c b/docs/examples/crawler.c index 21cdb5fcff..595375614e 100644 --- a/docs/examples/crawler.c +++ b/docs/examples/crawler.c @@ -47,7 +47,7 @@ static int max_total = 20000; static int max_requests = 500; static size_t max_link_per_page = 5; static int follow_relative_links = 0; -static const char *start_page = "https://www.reuters.com/"; +static const char start_page[] = "https://www.reuters.com/"; static int pending_interrupt = 0; static void sighandler(int dummy) diff --git a/docs/examples/ephiperfifo.c b/docs/examples/ephiperfifo.c index 292bfc741e..de86690ef4 100644 --- a/docs/examples/ephiperfifo.c +++ b/docs/examples/ephiperfifo.c @@ -303,7 +303,9 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { struct GlobalInfo *g = (struct GlobalInfo *)cbp; struct SockInfo *fdp = (struct SockInfo *)sockp; - const char *whatstr[] = { "none", "IN", "OUT", "INOUT", "REMOVE" }; + static const char * const whatstr[] = { + "none", "IN", "OUT", "INOUT", "REMOVE" + }; fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); if(what == CURL_POLL_REMOVE) { @@ -407,7 +409,7 @@ static void fifo_cb(struct GlobalInfo *g, int revents) static int init_fifo(struct GlobalInfo *g) { struct stat st; - static const char *fifo = "hiper.fifo"; + static const char fifo[] = "hiper.fifo"; curl_socket_t sockfd; struct epoll_event epev; diff --git a/docs/examples/evhiperfifo.c b/docs/examples/evhiperfifo.c index 079eab1e8a..32f92f9415 100644 --- a/docs/examples/evhiperfifo.c +++ b/docs/examples/evhiperfifo.c @@ -267,7 +267,9 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { struct GlobalInfo *g = (struct GlobalInfo *)cbp; struct SockInfo *fdp = (struct SockInfo *)sockp; - const char *whatstr[] = { "none", "IN", "OUT", "INOUT", "REMOVE" }; + static const char * const whatstr[] = { + "none", "IN", "OUT", "INOUT", "REMOVE" + }; printf("%s e %p s %d what %d cbp %p sockp %p\n", __PRETTY_FUNCTION__, e, s, what, cbp, sockp); @@ -378,7 +380,7 @@ static void fifo_cb(EV_P_ struct ev_io *w, int revents) static int init_fifo(struct GlobalInfo *g) { struct stat st; - static const char *fifo = "hiper.fifo"; + static const char fifo[] = "hiper.fifo"; curl_socket_t sockfd; fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo); diff --git a/docs/examples/ghiper.c b/docs/examples/ghiper.c index fd6041761e..79516ccd82 100644 --- a/docs/examples/ghiper.c +++ b/docs/examples/ghiper.c @@ -258,7 +258,9 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { struct GlobalInfo *g = (struct GlobalInfo *)cbp; struct SockInfo *fdp = (struct SockInfo *)sockp; - static const char *whatstr[] = { "none", "IN", "OUT", "INOUT", "REMOVE" }; + static const char * const whatstr[] = { + "none", "IN", "OUT", "INOUT", "REMOVE" + }; MSG_OUT("socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); if(what == CURL_POLL_REMOVE) { @@ -395,8 +397,8 @@ static gboolean fifo_cb(GIOChannel *ch, GIOCondition condition, gpointer data) int init_fifo(void) { + static const char fifo[] = "hiper.fifo"; struct stat st; - const char *fifo = "hiper.fifo"; int socket; if(!lstat(fifo, &st)) { diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index 96719530cf..cc27799012 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -270,7 +270,9 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { struct GlobalInfo *g = (struct GlobalInfo *)cbp; struct SockInfo *fdp = (struct SockInfo *)sockp; - const char *whatstr[] = { "none", "IN", "OUT", "INOUT", "REMOVE" }; + static const char * const whatstr[] = { + "none", "IN", "OUT", "INOUT", "REMOVE" + }; fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); if(what == CURL_POLL_REMOVE) { @@ -376,7 +378,7 @@ static void fifo_cb(int fd, short event, void *arg) } /* Create a named pipe and tell libevent to monitor it */ -static const char *fifo = "hiper.fifo"; +static const char fifo[] = "hiper.fifo"; static int init_fifo(struct GlobalInfo *g) { struct stat st; diff --git a/docs/examples/imap-append.c b/docs/examples/imap-append.c index 77cf2bc02a..c530bbb9c8 100644 --- a/docs/examples/imap-append.c +++ b/docs/examples/imap-append.c @@ -40,7 +40,7 @@ #define TO "" #define CC "" -static const char *payload_text = +static const char payload_text[] = "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n" "To: " TO "\r\n" "From: " FROM "(Example User)\r\n" @@ -111,7 +111,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); - filesize = strlen(payload_text); + filesize = sizeof(payload_text) - 1; if(filesize <= LONG_MAX) infilesize = (long)filesize; curl_easy_setopt(curl, CURLOPT_INFILESIZE, infilesize); diff --git a/docs/examples/maxconnects.c b/docs/examples/maxconnects.c index 7ef29828ea..b52f1fcc3f 100644 --- a/docs/examples/maxconnects.c +++ b/docs/examples/maxconnects.c @@ -39,7 +39,7 @@ int main(void) curl = curl_easy_init(); if(curl) { - const char *urls[] = { + static const char * const urls[] = { "https://example.com/", "https://curl.se/", "https://www.example/", diff --git a/docs/examples/postinmemory.c b/docs/examples/postinmemory.c index c4d9abcc11..7f18e8e5f5 100644 --- a/docs/examples/postinmemory.c +++ b/docs/examples/postinmemory.c @@ -61,7 +61,7 @@ int main(void) CURL *curl; CURLcode result; struct MemoryStruct chunk; - static const char *postthis = "Field=1&Field=2&Field=3"; + static const char postthis[] = "Field=1&Field=2&Field=3"; result = curl_global_init(CURL_GLOBAL_ALL); if(result != CURLE_OK) @@ -87,7 +87,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis); /* if we do not provide POSTFIELDSIZE, libcurl calls strlen() by itself */ - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis)); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)sizeof(postthis) - 1); /* Perform the request, result gets the return code */ result = curl_easy_perform(curl); diff --git a/docs/examples/sendrecv.c b/docs/examples/sendrecv.c index 2777ca0a6d..a3539adb3c 100644 --- a/docs/examples/sendrecv.c +++ b/docs/examples/sendrecv.c @@ -77,8 +77,8 @@ int main(void) { CURL *curl; /* Minimalistic http request */ - const char *request = "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n"; - size_t request_len = strlen(request); + static const char request[] = "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n"; + static const size_t request_len = sizeof(request) - 1; CURLcode result = curl_global_init(CURL_GLOBAL_ALL); if(result != CURLE_OK) diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index c9fee6c2ba..011eae1aea 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -53,9 +53,9 @@ int main(void) /* init the curl session */ curl = curl_easy_init(); if(curl) { - static const char *headerfilename = "head.out"; + static const char headerfilename[] = "head.out"; FILE *headerfile; - static const char *bodyfilename = "body.out"; + static const char bodyfilename[] = "body.out"; FILE *bodyfile; /* set URL to get */ diff --git a/docs/examples/sftpuploadresume.c b/docs/examples/sftpuploadresume.c index 153883640b..e5d14a8459 100644 --- a/docs/examples/sftpuploadresume.c +++ b/docs/examples/sftpuploadresume.c @@ -134,8 +134,8 @@ int main(void) curl = curl_easy_init(); if(curl) { - const char *remote = "sftp://user:pass@example.com/path/filename"; - const char *filename = "filename"; + static const char remote[] = "sftp://user:pass@example.com/path/filename"; + static const char filename[] = "filename"; if(!sftpResumeUpload(curl, remote, filename)) { printf("resumed upload using curl %s failed\n", curl_version()); diff --git a/docs/examples/simplepost.c b/docs/examples/simplepost.c index d2540151ce..fb85677c31 100644 --- a/docs/examples/simplepost.c +++ b/docs/examples/simplepost.c @@ -32,7 +32,7 @@ int main(void) { - static const char *postthis = "moo mooo moo moo"; + static const char postthis[] = "moo mooo moo moo"; CURL *curl; @@ -46,7 +46,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis); /* if we do not provide POSTFIELDSIZE, libcurl calls strlen() by itself */ - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis)); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)sizeof(postthis) - 1); /* Perform the request, result gets the return code */ result = curl_easy_perform(curl); diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index 24e08c4c71..45db65a05d 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -55,9 +55,9 @@ int main(void) FILE *headerfile; const char *pPassphrase = NULL; - static const char *pCertFile = "testcert.pem"; - static const char *pCACertFile = "cacert.pem"; - static const char *pHeaderFile = "dumpit"; + static const char pCertFile[] = "testcert.pem"; + static const char pCACertFile[] = "cacert.pem"; + static const char pHeaderFile[] = "dumpit"; const char *pKeyName; const char *pKeyType; diff --git a/docs/examples/smtp-authzid.c b/docs/examples/smtp-authzid.c index fe91ba5e63..0260452990 100644 --- a/docs/examples/smtp-authzid.c +++ b/docs/examples/smtp-authzid.c @@ -48,7 +48,7 @@ #define SENDER_MAIL "Kurt " SENDER_ADDR #define TO_MAIL "A Receiver " TO_ADDR -static const char *payload_text = +static const char payload_text[] = "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n" "To: " TO_MAIL "\r\n" "From: " FROM_MAIL "\r\n" diff --git a/docs/examples/smtp-mail.c b/docs/examples/smtp-mail.c index b1590fd3af..618123ab5e 100644 --- a/docs/examples/smtp-mail.c +++ b/docs/examples/smtp-mail.c @@ -45,7 +45,7 @@ #define TO_MAIL "A Receiver " TO_ADDR #define CC_MAIL "John CC Smith " CC_ADDR -static const char *payload_text = +static const char payload_text[] = "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n" "To: " TO_MAIL "\r\n" "From: " FROM_MAIL "\r\n" diff --git a/docs/examples/smtp-mime.c b/docs/examples/smtp-mime.c index 0ddba4ebb7..4d54532559 100644 --- a/docs/examples/smtp-mime.c +++ b/docs/examples/smtp-mime.c @@ -41,7 +41,7 @@ #define TO "" #define CC "" -static const char *headers_text[] = { +static const char * const headers_text[] = { "Date: Tue, 22 Aug 2017 14:08:43 +0100", "To: " TO, "From: " FROM " (Example User)", @@ -82,7 +82,7 @@ int main(void) curl_mime *mime; curl_mime *alt; curl_mimepart *part; - const char **cpp; + const char * const *cpp; /* This is the URL for your mailserver */ curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com"); diff --git a/docs/examples/smtp-multi.c b/docs/examples/smtp-multi.c index 86545a1ef3..9d76a57fe7 100644 --- a/docs/examples/smtp-multi.c +++ b/docs/examples/smtp-multi.c @@ -38,7 +38,7 @@ #define TO_MAIL "" #define CC_MAIL "" -static const char *payload_text = +static const char payload_text[] = "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n" "To: " TO_MAIL "\r\n" "From: " FROM_MAIL "\r\n" diff --git a/docs/examples/smtp-ssl.c b/docs/examples/smtp-ssl.c index 9cac9ecd52..172f66b8da 100644 --- a/docs/examples/smtp-ssl.c +++ b/docs/examples/smtp-ssl.c @@ -42,7 +42,7 @@ #define TO_MAIL "" #define CC_MAIL "" -static const char *payload_text = +static const char payload_text[] = "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n" "To: " TO_MAIL "\r\n" "From: " FROM_MAIL "\r\n" diff --git a/docs/examples/smtp-tls.c b/docs/examples/smtp-tls.c index da452318a6..c3c992717b 100644 --- a/docs/examples/smtp-tls.c +++ b/docs/examples/smtp-tls.c @@ -42,7 +42,7 @@ #define TO_MAIL "" #define CC_MAIL "" -static const char *payload_text = +static const char payload_text[] = "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n" "To: " TO_MAIL "\r\n" "From: " FROM_MAIL "\r\n" diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index 2c7501d4db..8e9adf1f3f 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -99,10 +99,10 @@ static int AutoSyncTime; static SYSTEMTIME SYSTime; static SYSTEMTIME LOCALTime; -static const char *DayStr[] = { +static const char * const DayStr[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; -static const char *MthStr[] = { +static const char * const MthStr[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; diff --git a/docs/examples/url2file.c b/docs/examples/url2file.c index ce8805a40e..1216575638 100644 --- a/docs/examples/url2file.c +++ b/docs/examples/url2file.c @@ -44,7 +44,7 @@ static size_t write_cb(char *ptr, size_t size, size_t nmemb, void *stream) int main(int argc, const char *argv[]) { - static const char *pagefilename = "page.out"; + static const char pagefilename[] = "page.out"; CURLcode result; CURL *curl; diff --git a/docs/examples/websocket-updown.c b/docs/examples/websocket-updown.c index 85a7e74ea3..495c4b7166 100644 --- a/docs/examples/websocket-updown.c +++ b/docs/examples/websocket-updown.c @@ -88,7 +88,7 @@ int main(int argc, const char *argv[]) { CURL *curl; struct read_ctx rctx; - const char *payload = "Hello, friend!"; + static const char payload[] = "Hello, friend!"; CURLcode result = curl_global_init(CURL_GLOBAL_ALL); if(result != CURLE_OK) @@ -108,7 +108,7 @@ int main(int argc, const char *argv[]) curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb); /* tell curl that we want to send the payload */ rctx.curl = curl; - rctx.blen = strlen(payload); + rctx.blen = sizeof(payload) - 1; memcpy(rctx.buf, payload, rctx.blen); curl_easy_setopt(curl, CURLOPT_READDATA, &rctx); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); diff --git a/lib/cf-h1-proxy.c b/lib/cf-h1-proxy.c index f1e5c7a42a..b425249588 100644 --- a/lib/cf-h1-proxy.c +++ b/lib/cf-h1-proxy.c @@ -329,7 +329,7 @@ static CURLcode on_resp_header_udp(struct Curl_cfilter *cf, k->httpcode); } else { - const char *p = header + strlen("Content-Length:"); + const char *p = header + CURL_CSTRLEN("Content-Length:"); if(curlx_str_numblanks(&p, &ts->cl)) { failf(data, "Unsupported Content-Length value"); return CURLE_WEIRD_SERVER_REPLY; @@ -419,7 +419,7 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf, k->httpcode); } else { - const char *p = header + strlen("Content-Length:"); + const char *p = header + CURL_CSTRLEN("Content-Length:"); if(curlx_str_numblanks(&p, &ts->cl)) { failf(data, "Unsupported Content-Length value"); return CURLE_WEIRD_SERVER_REPLY; diff --git a/lib/cf-h2-proxy.c b/lib/cf-h2-proxy.c index be303ffd3e..86e04fc0ec 100644 --- a/lib/cf-h2-proxy.c +++ b/lib/cf-h2-proxy.c @@ -574,7 +574,7 @@ static int proxy_h2_on_header(nghttp2_session *session, return 0; } - if(namelen == sizeof(HTTP_PSEUDO_STATUS) - 1 && + if(namelen == CURL_CSTRLEN(HTTP_PSEUDO_STATUS) && !memcmp(HTTP_PSEUDO_STATUS, name, namelen)) { int http_status; struct http_resp *resp; diff --git a/lib/curl_setup.h b/lib/curl_setup.h index a91b912f3e..e6d5b8f694 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -1291,10 +1291,14 @@ typedef unsigned int curl_bit; #define CURLMAX(x, y) ((x) > (y) ? (x) : (y)) #define CURLMIN(x, y) ((x) < (y) ? (x) : (y)) +/* Convenience macro to provide the length of a string literal size without + the null-terminator. Equivalent to strlen() for constant strings. */ +#define CURL_CSTRLEN(x) (sizeof(x) - 1) + /* A convenience macro to provide both the string literal and the length of the string literal in one go, useful for functions that take "string,len" as their argument */ -#define STRCONST(x) x, sizeof(x) - 1 +#define STRCONST(x) x, CURL_CSTRLEN(x) #define CURL_ARRAYSIZE(A) (sizeof(A) / sizeof((A)[0])) diff --git a/lib/dict.c b/lib/dict.c index db25d5a721..2a0053e934 100644 --- a/lib/dict.c +++ b/lib/dict.c @@ -153,9 +153,9 @@ static CURLcode dict_do(struct Curl_easy *data, bool *done) if(result) return result; - if(curl_strnequal(path, DICT_MATCH, sizeof(DICT_MATCH) - 1) || - curl_strnequal(path, DICT_MATCH2, sizeof(DICT_MATCH2) - 1) || - curl_strnequal(path, DICT_MATCH3, sizeof(DICT_MATCH3) - 1)) { + if(curl_strnequal(path, DICT_MATCH, CURL_CSTRLEN(DICT_MATCH)) || + curl_strnequal(path, DICT_MATCH2, CURL_CSTRLEN(DICT_MATCH2)) || + curl_strnequal(path, DICT_MATCH3, CURL_CSTRLEN(DICT_MATCH3))) { word = strchr(path, ':'); if(word) { @@ -200,9 +200,9 @@ static CURLcode dict_do(struct Curl_easy *data, bool *done) } Curl_xfer_setup_recv(data, FIRSTSOCKET, -1); } - else if(curl_strnequal(path, DICT_DEFINE, sizeof(DICT_DEFINE) - 1) || - curl_strnequal(path, DICT_DEFINE2, sizeof(DICT_DEFINE2) - 1) || - curl_strnequal(path, DICT_DEFINE3, sizeof(DICT_DEFINE3) - 1)) { + else if(curl_strnequal(path, DICT_DEFINE, CURL_CSTRLEN(DICT_DEFINE)) || + curl_strnequal(path, DICT_DEFINE2, CURL_CSTRLEN(DICT_DEFINE2)) || + curl_strnequal(path, DICT_DEFINE3, CURL_CSTRLEN(DICT_DEFINE3))) { word = strchr(path, ':'); if(word) { diff --git a/lib/http.c b/lib/http.c index c8c0084233..4feb930069 100644 --- a/lib/http.c +++ b/lib/http.c @@ -5026,7 +5026,7 @@ CURLcode Curl_http_req_to_h2(struct dynhds *h2_headers, if(e->namelen == 2 && curl_strequal("TE", e->name)) { if(http_TE_has_token(e->value, "trailers")) result = Curl_dynhds_add(h2_headers, e->name, e->namelen, - "trailers", sizeof("trailers") - 1); + "trailers", CURL_CSTRLEN("trailers")); } else if(h2_permissible_field(e)) { result = Curl_dynhds_add(h2_headers, e->name, e->namelen, diff --git a/lib/http2.c b/lib/http2.c index a63fc4a59c..8d4a93cb58 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -1427,7 +1427,7 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame, if(frame->hd.type == NGHTTP2_PUSH_PROMISE) { char *h; - if((namelen == (sizeof(HTTP_PSEUDO_AUTHORITY) - 1)) && + if((namelen == CURL_CSTRLEN(HTTP_PSEUDO_AUTHORITY)) && !strncmp(HTTP_PSEUDO_AUTHORITY, (const char *)name, namelen)) { /* pseudo headers are lower case */ int rc = 0; @@ -1503,7 +1503,7 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame, return 0; } - if(namelen == sizeof(HTTP_PSEUDO_STATUS) - 1 && + if(namelen == CURL_CSTRLEN(HTTP_PSEUDO_STATUS) && !memcmp(HTTP_PSEUDO_STATUS, name, namelen)) { /* nghttp2 guarantees :status is received first and only once. */ char buffer[32]; diff --git a/lib/http_aws_sigv4.c b/lib/http_aws_sigv4.c index d4ad7cc5f0..bff66a9582 100644 --- a/lib/http_aws_sigv4.c +++ b/lib/http_aws_sigv4.c @@ -623,7 +623,7 @@ static CURLcode calc_s3_payload_hash(struct Curl_easy *data, } else { /* Fall back to s3's UNSIGNED-PAYLOAD */ - size_t len = sizeof(S3_UNSIGNED_PAYLOAD) - 1; + size_t len = CURL_CSTRLEN(S3_UNSIGNED_PAYLOAD); DEBUGASSERT(len < SHA256_HEX_LENGTH); /* 16 < 65 */ memcpy(sha_hex, S3_UNSIGNED_PAYLOAD, len); sha_hex[len] = 0; @@ -1143,7 +1143,7 @@ static CURLcode sign_and_set_auth_headers(struct Curl_easy *data, goto fail; /* provider 0 uppercase */ - Curl_strntoupper(&auth_headers[sizeof("Authorization: ") - 1], + Curl_strntoupper(&auth_headers[CURL_CSTRLEN("Authorization: ")], curlx_str(provider0), curlx_strlen(provider0)); curlx_free(data->req.hd_auth); diff --git a/lib/http_digest.c b/lib/http_digest.c index 31a9db35a8..90350a1d1e 100644 --- a/lib/http_digest.c +++ b/lib/http_digest.c @@ -54,7 +54,7 @@ CURLcode Curl_input_digest(struct Curl_easy *data, if(!checkprefix("Digest", header) || !ISBLANK(header[6])) return CURLE_AUTH_ERROR; - header += strlen("Digest"); + header += CURL_CSTRLEN("Digest"); curlx_str_passblanks(&header); return Curl_auth_decode_digest_http_message(header, digest); diff --git a/lib/http_negotiate.c b/lib/http_negotiate.c index 891369b5bc..7aaa6878d1 100644 --- a/lib/http_negotiate.c +++ b/lib/http_negotiate.c @@ -83,7 +83,7 @@ CURLcode Curl_input_negotiate(struct Curl_easy *data, struct connectdata *conn, return CURLE_OUT_OF_MEMORY; /* Obtain the input token, if any */ - header += strlen("Negotiate"); + header += CURL_CSTRLEN("Negotiate"); curlx_str_passblanks(&header); len = strlen(header); diff --git a/lib/http_ntlm.c b/lib/http_ntlm.c index dc9911fdac..b0a73a6c8a 100644 --- a/lib/http_ntlm.c +++ b/lib/http_ntlm.c @@ -65,7 +65,7 @@ CURLcode Curl_input_ntlm(struct Curl_easy *data, if(!ntlm) return CURLE_OUT_OF_MEMORY; - header += strlen("NTLM"); + header += CURL_CSTRLEN("NTLM"); curlx_str_passblanks(&header); if(*header) { unsigned char *hdr; diff --git a/lib/http_proxy.c b/lib/http_proxy.c index aa20a52ebe..c658b82478 100644 --- a/lib/http_proxy.c +++ b/lib/http_proxy.c @@ -215,7 +215,7 @@ static CURLcode http_proxy_create_CONNECT(struct httpreq **preq, goto out; } - result = Curl_http_req_make(&req, "CONNECT", sizeof("CONNECT") - 1, + result = Curl_http_req_make(&req, "CONNECT", CURL_CSTRLEN("CONNECT"), NULL, 0, authority, strlen(authority), NULL, 0); if(result) @@ -340,7 +340,7 @@ static CURLcode http_proxy_create_CONNECTUDP(struct httpreq **preq, } if(ver == PROXY_HTTP_V1) { - result = Curl_http_req_make(&req, "GET", sizeof("GET")-1, + result = Curl_http_req_make(&req, "GET", CURL_CSTRLEN("GET"), proxy_scheme, strlen(proxy_scheme), authority, strlen(authority), path, strlen(path)); @@ -348,7 +348,7 @@ static CURLcode http_proxy_create_CONNECTUDP(struct httpreq **preq, goto out; } else if(ver == PROXY_HTTP_V2 || ver == PROXY_HTTP_V3) { - result = Curl_http_req_make(&req, "CONNECT", sizeof("CONNECT") - 1, + result = Curl_http_req_make(&req, "CONNECT", CURL_CSTRLEN("CONNECT"), proxy_scheme, strlen(proxy_scheme), authority, strlen(authority), path, strlen(path)); diff --git a/lib/imap.c b/lib/imap.c index 6a48f85152..8f0c297715 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -1357,7 +1357,7 @@ static CURLcode imap_state_select_resp(struct Curl_easy *data, size_t len = curlx_dyn_len(&imapc->pp.recvbuf); if((len >= 18) && checkprefix("OK [UIDVALIDITY ", &line[2])) { curl_off_t value; - const char *p = &line[2] + strlen("OK [UIDVALIDITY "); + const char *p = &line[2] + CURL_CSTRLEN("OK [UIDVALIDITY "); if(!curlx_str_number(&p, &value, UINT_MAX)) { imapc->mb_uidvalidity = (unsigned int)value; imapc->mb_uidvalidity_set = TRUE; diff --git a/lib/ldap.c b/lib/ldap.c index dac472d4c9..a7c1fe8c83 100644 --- a/lib/ldap.c +++ b/lib/ldap.c @@ -976,9 +976,9 @@ void Curl_ldap_version(char *buf, size_t bufsz) curl_msnprintf(buf, bufsz, "WinLDAP"); #else #ifdef LDAP_OPT_X_TLS_PASSPHRASE - static const char *flavor = "/Apple"; + static const char flavor[] = "/Apple"; #else - static const char *flavor = ""; + static const char flavor[] = ""; #endif LDAPAPIInfo api; api.ldapai_info_version = LDAP_API_INFO_VERSION; diff --git a/lib/mqtt.c b/lib/mqtt.c index a9cdf21498..0858fd65f6 100644 --- a/lib/mqtt.c +++ b/lib/mqtt.c @@ -276,7 +276,7 @@ static CURLcode mqtt_connect(struct Curl_easy *data) size_t start_user = 0; size_t start_pwd = 0; char client_id[MQTT_CLIENTID_LEN + 1] = "curl"; - const size_t clen = strlen("curl"); + const size_t clen = CURL_CSTRLEN("curl"); char *packet = NULL; /* extracting username from request */ @@ -627,7 +627,7 @@ static bool mqtt_decode_len(size_t *lenp, const unsigned char *buf, } #if defined(DEBUGBUILD) && defined(CURLVERBOSE) -static const char *statenames[] = { +static const char * const statenames[] = { "MQTT_FIRST", "MQTT_REMAINING_LENGTH", "MQTT_CONNACK", diff --git a/lib/progress.c b/lib/progress.c index 3c0f3d57d7..b6322461d5 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -91,7 +91,7 @@ UNITTEST char *max6out(curl_off_t bytes, char *max6, size_t mlen) if(bytes < 100000) curl_msnprintf(max6, mlen, "%6" CURL_FORMAT_CURL_OFF_T, bytes); else { - const char unit[] = { 'k', 'M', 'G', 'T', 'P', 'E', 0 }; + static const char unit[] = { 'k', 'M', 'G', 'T', 'P', 'E', 0 }; int k = 0; curl_off_t nbytes; curl_off_t rest; diff --git a/lib/smb.c b/lib/smb.c index 2d1a859aa1..4299190ff5 100644 --- a/lib/smb.c +++ b/lib/smb.c @@ -654,9 +654,10 @@ static CURLcode smb_send_negotiate(struct Curl_easy *data, struct smb_conn *smbc, struct smb_request *req) { - const char *msg = "\x00\x0c\x00\x02NT LM 0.12"; + static const char msg[] = "\x00\x0c\x00\x02NT LM 0.12"; - return smb_send_message(data, smbc, req, SMB_COM_NEGOTIATE, msg, 15); + return smb_send_message(data, smbc, req, SMB_COM_NEGOTIATE, msg, + sizeof(msg)); } static CURLcode smb_send_setup(struct Curl_easy *data) @@ -678,7 +679,7 @@ static CURLcode smb_send_setup(struct Curl_easy *data) byte_count = sizeof(lm) + sizeof(nt) + strlen(smbc->user) + strlen(smbc->domain) + - strlen(CURL_OS) + strlen(CLIENTNAME) + 4; /* 4 null chars */ + CURL_CSTRLEN(CURL_OS) + CURL_CSTRLEN(CLIENTNAME) + 4; /* 4 null chars */ if(byte_count > sizeof(msg.bytes)) return CURLE_FILESIZE_EXCEEDED; @@ -724,7 +725,7 @@ static CURLcode smb_send_tree_connect(struct Curl_easy *data, char *p = msg.bytes; const size_t byte_count = strlen(conn->origin->hostname) + strlen(smbc->share) + - strlen(SERVICENAME) + 5; /* 2 nulls and 3 backslashes */ + CURL_CSTRLEN(SERVICENAME) + 5; /* 2 nulls and 3 backslashes */ if(byte_count > sizeof(msg.bytes)) return CURLE_FILESIZE_EXCEEDED; diff --git a/lib/tftp.c b/lib/tftp.c index d5c85a3100..c101edebed 100644 --- a/lib/tftp.c +++ b/lib/tftp.c @@ -278,7 +278,7 @@ static CURLcode tftp_parse_option_ack(struct tftp_conn *state, infof(data, "got option=(%s) value=(%s)", option, value); - if((strlen(TFTP_OPTION_BLKSIZE) == olen) && + if((CURL_CSTRLEN(TFTP_OPTION_BLKSIZE) == olen) && checkprefix(TFTP_OPTION_BLKSIZE, option)) { curl_off_t blksize; if(curlx_str_number(&value, &blksize, TFTP_BLKSIZE_MAX)) { @@ -308,7 +308,7 @@ static CURLcode tftp_parse_option_ack(struct tftp_conn *state, infof(data, "blksize parsed from OACK (%u) requested (%u)", state->blksize, state->requested_blksize); } - else if((strlen(TFTP_OPTION_TSIZE) == olen) && + else if((CURL_CSTRLEN(TFTP_OPTION_TSIZE) == olen) && checkprefix(TFTP_OPTION_TSIZE, option)) { curl_off_t tsize = 0; /* tsize should be ignored on upload: Who cares about the size of the diff --git a/lib/vquic/cf-quiche.c b/lib/vquic/cf-quiche.c index c23b810254..bfc68adf14 100644 --- a/lib/vquic/cf-quiche.c +++ b/lib/vquic/cf-quiche.c @@ -1298,9 +1298,8 @@ static CURLcode cf_quiche_ctx_open(struct Curl_cfilter *cf, 10 * QUIC_MAX_STREAMS * H3_STREAM_WINDOW_SIZE); quiche_config_set_max_stream_window(ctx->cfg, 10 * H3_STREAM_WINDOW_SIZE); quiche_config_set_application_protos(ctx->cfg, - (uint8_t *)CURL_UNCONST(QUICHE_H3_APPLICATION_PROTOCOL), - sizeof(QUICHE_H3_APPLICATION_PROTOCOL) - - 1); + (uint8_t *)CURL_UNCONST(QUICHE_H3_APPLICATION_PROTOCOL), + CURL_CSTRLEN(QUICHE_H3_APPLICATION_PROTOCOL)); result = Curl_vquic_tls_init(&ctx->tls, cf, data, &ctx->ssl_peer, &ALPN_SPEC_H3, NULL, NULL, cf, NULL); @@ -1351,7 +1350,7 @@ static CURLcode cf_quiche_ctx_open(struct Curl_cfilter *cf, unsigned alpn_len, offset = 0; /* Replace each ALPN length prefix by a comma. */ - while(offset < sizeof(alpn_protocols) - 1) { + while(offset < CURL_CSTRLEN(alpn_protocols)) { alpn_len = alpn_protocols[offset]; alpn_protocols[offset] = ','; offset += 1 + alpn_len; diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index effcc9beaf..940c678358 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -1768,7 +1768,7 @@ static CURLcode ssh_state_sftp_realpath(struct Curl_easy *data, return CURLE_FAILED_INIT; rc = libssh2_sftp_symlink_ex(sshc->sftp_session, ".", - curlx_uztoui(strlen(".")), + curlx_uztoui(CURL_CSTRLEN(".")), sshp->readdir_filename, CURL_PATH_MAX, LIBSSH2_SFTP_REALPATH); if(rc == LIBSSH2_ERROR_EAGAIN) diff --git a/lib/vtls/cipher_suite.c b/lib/vtls/cipher_suite.c index 197055fc0d..2c6a0c02d0 100644 --- a/lib/vtls/cipher_suite.c +++ b/lib/vtls/cipher_suite.c @@ -48,7 +48,7 @@ /* Text for cipher suite parts (max 64 entries), keep indexes below in sync with this! */ -static const char *cs_txt = +static const char cs_txt[] = "\0" "TLS" "\0" "WITH" "\0" diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c index 423179172f..92607b1135 100644 --- a/lib/vtls/gtls.c +++ b/lib/vtls/gtls.c @@ -591,7 +591,7 @@ static struct gtls_shared_creds *gtls_get_cached_creds(struct Curl_cfilter *cf, if(data->multi) { shared_creds = Curl_hash_pick(&data->multi->proto_hash, CURL_UNCONST(MPROTO_GTLS_X509_KEY), - sizeof(MPROTO_GTLS_X509_KEY) - 1); + CURL_CSTRLEN(MPROTO_GTLS_X509_KEY)); if(shared_creds && shared_creds->creds && !gtls_shared_creds_expired(data, shared_creds) && !gtls_shared_creds_different(cf, shared_creds)) { @@ -604,7 +604,7 @@ static struct gtls_shared_creds *gtls_get_cached_creds(struct Curl_cfilter *cf, static void gtls_shared_creds_hash_free(void *key, size_t key_len, void *p) { struct gtls_shared_creds *sc = p; - DEBUGASSERT(key_len == (sizeof(MPROTO_GTLS_X509_KEY) - 1)); + DEBUGASSERT(key_len == CURL_CSTRLEN(MPROTO_GTLS_X509_KEY)); DEBUGASSERT(!memcmp(MPROTO_GTLS_X509_KEY, key, key_len)); (void)key; (void)key_len; @@ -635,7 +635,7 @@ static void gtls_set_cached_creds(struct Curl_cfilter *cf, if(!Curl_hash_add2(&data->multi->proto_hash, CURL_UNCONST(MPROTO_GTLS_X509_KEY), - sizeof(MPROTO_GTLS_X509_KEY) - 1, + CURL_CSTRLEN(MPROTO_GTLS_X509_KEY), sc, gtls_shared_creds_hash_free)) { Curl_gtls_shared_creds_free(&sc); /* down reference again */ return; diff --git a/lib/vtls/keylog.h b/lib/vtls/keylog.h index b09fcc6f4d..f95dfeae2d 100644 --- a/lib/vtls/keylog.h +++ b/lib/vtls/keylog.h @@ -25,7 +25,7 @@ ***************************************************************************/ #include "curl_setup.h" -#define KEYLOG_LABEL_MAXLEN (sizeof("CLIENT_HANDSHAKE_TRAFFIC_SECRET") - 1) +#define KEYLOG_LABEL_MAXLEN CURL_CSTRLEN("CLIENT_HANDSHAKE_TRAFFIC_SECRET") #define CLIENT_RANDOM_SIZE 32 diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c index 9f576a9d52..12903038f1 100644 --- a/lib/vtls/openssl.c +++ b/lib/vtls/openssl.c @@ -248,7 +248,7 @@ static CURLcode X509V3_ext(struct Curl_easy *data, if(asn1_object_dump(obj, namebuf, sizeof(namebuf))) /* make sure the name is null-terminated */ - namebuf[sizeof(namebuf) - 1] = 0; + namebuf[CURL_CSTRLEN(namebuf)] = 0; if(!X509V3_EXT_print(bio_out, ext, 0, 0)) ASN1_STRING_print(bio_out, @@ -1176,7 +1176,7 @@ static int engineload(struct Curl_easy *data, } if(data->state.engine) { - const char *cmd_name = "LOAD_CERT_CTRL"; + static const char cmd_name[] = "LOAD_CERT_CTRL"; struct { const char *cert_id; X509 *cert; @@ -2965,7 +2965,7 @@ static CURLcode ossl_windows_load_anchors(struct Curl_cfilter *cf, https://stackoverflow.com/questions/9507184/ https://github.com/d3x0r/SACK/blob/ff15424d3c581b86d40f818532e5a400c516d39d/src/netlib/ssl_layer.c#L1410 https://datatracker.ietf.org/doc/html/rfc5280 */ - const char *win_stores[] = { + static const char * const win_stores[] = { "ROOT", /* Trusted Root Certification Authorities */ "CA" /* Intermediate Certification Authorities */ }; @@ -3180,7 +3180,7 @@ struct ossl_x509_share { static void oss_x509_share_free(void *key, size_t key_len, void *p) { struct ossl_x509_share *share = p; - DEBUGASSERT(key_len == (sizeof(MPROTO_OSSL_X509_KEY) - 1)); + DEBUGASSERT(key_len == CURL_CSTRLEN(MPROTO_OSSL_X509_KEY)); DEBUGASSERT(!memcmp(MPROTO_OSSL_X509_KEY, key, key_len)); (void)key; (void)key_len; @@ -3231,7 +3231,7 @@ static X509_STORE *ossl_get_cached_x509_store(struct Curl_cfilter *cf, *pempty = TRUE; share = multi ? Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_OSSL_X509_KEY), - sizeof(MPROTO_OSSL_X509_KEY) - 1) : NULL; + CURL_CSTRLEN(MPROTO_OSSL_X509_KEY)) : NULL; if(share && share->store && !ossl_cached_x509_store_expired(data, share) && !ossl_cached_x509_store_different(cf, data, share)) { @@ -3256,7 +3256,7 @@ static void ossl_set_cached_x509_store(struct Curl_cfilter *cf, return; share = Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_OSSL_X509_KEY), - sizeof(MPROTO_OSSL_X509_KEY) - 1); + CURL_CSTRLEN(MPROTO_OSSL_X509_KEY)); if(!share) { share = curlx_calloc(1, sizeof(*share)); @@ -3264,7 +3264,7 @@ static void ossl_set_cached_x509_store(struct Curl_cfilter *cf, return; if(!Curl_hash_add2(&multi->proto_hash, CURL_UNCONST(MPROTO_OSSL_X509_KEY), - sizeof(MPROTO_OSSL_X509_KEY) - 1, + CURL_CSTRLEN(MPROTO_OSSL_X509_KEY), share, oss_x509_share_free)) { curlx_free(share); return; @@ -5283,7 +5283,7 @@ static CURLcode ossl_get_channel_binding(struct Curl_easy *data, unsigned int length; unsigned char buf[EVP_MAX_MD_SIZE]; - const char prefix[] = "tls-server-end-point:"; + static const char prefix[] = "tls-server-end-point:"; struct connectdata *conn = data->conn; struct Curl_cfilter *cf = conn->cfilter[sockindex]; struct ossl_ctx *octx = NULL; @@ -5405,7 +5405,7 @@ static CURLcode ossl_get_channel_binding(struct Curl_easy *data, } /* Append "tls-server-end-point:" */ - result = curlx_dyn_addn(binding, prefix, sizeof(prefix) - 1); + result = curlx_dyn_addn(binding, prefix, CURL_CSTRLEN(prefix)); if(result) goto out; @@ -5423,9 +5423,9 @@ size_t Curl_ossl_version(char *buffer, size_t size) char *p; size_t count; const char *ver = OpenSSL_version(OPENSSL_VERSION); - const char expected[] = OSSL_PACKAGE " "; /* ie "LibreSSL " */ - if(curl_strnequal(ver, expected, sizeof(expected) - 1)) { - ver += sizeof(expected) - 1; + static const char expected[] = OSSL_PACKAGE " "; /* ie "LibreSSL " */ + if(curl_strnequal(ver, expected, CURL_CSTRLEN(expected))) { + ver += CURL_CSTRLEN(expected); } count = curl_msnprintf(buffer, size, "%s/%s", OSSL_PACKAGE, ver); for(p = buffer; *p; ++p) { diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c index 17c1c8d195..f55784c624 100644 --- a/lib/vtls/schannel.c +++ b/lib/vtls/schannel.c @@ -291,9 +291,9 @@ static CURLcode set_ssl_ciphers(SCHANNEL_CRED *schannel_cred, char *ciphers, if(alg) algIds[algCount++] = (ALG_ID)alg; else if(!strncmp(startCur, "USE_STRONG_CRYPTO", - sizeof("USE_STRONG_CRYPTO") - 1) || + CURL_CSTRLEN("USE_STRONG_CRYPTO")) || !strncmp(startCur, "SCH_USE_STRONG_CRYPTO", - sizeof("SCH_USE_STRONG_CRYPTO") - 1)) + CURL_CSTRLEN("SCH_USE_STRONG_CRYPTO"))) schannel_cred->dwFlags |= SCH_USE_STRONG_CRYPTO; else return CURLE_SSL_CIPHER; @@ -2736,7 +2736,7 @@ HCERTSTORE Curl_schannel_get_cached_cert_store(struct Curl_cfilter *cf, share = Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_SCHANNEL_CERT_SHARE_KEY), - sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY) - 1); + CURL_CSTRLEN(MPROTO_SCHANNEL_CERT_SHARE_KEY)); if(!share || !share->cert_store) { return NULL; } @@ -2785,7 +2785,7 @@ HCERTSTORE Curl_schannel_get_cached_cert_store(struct Curl_cfilter *cf, static void schannel_cert_share_free(void *key, size_t key_len, void *p) { struct schannel_cert_share *share = p; - DEBUGASSERT(key_len == (sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY) - 1)); + DEBUGASSERT(key_len == CURL_CSTRLEN(MPROTO_SCHANNEL_CERT_SHARE_KEY)); DEBUGASSERT(!memcmp(MPROTO_SCHANNEL_CERT_SHARE_KEY, key, key_len)); (void)key; (void)key_len; @@ -2828,7 +2828,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, share = Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_SCHANNEL_CERT_SHARE_KEY), - sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY) - 1); + CURL_CSTRLEN(MPROTO_SCHANNEL_CERT_SHARE_KEY)); if(!share) { share = curlx_calloc(1, sizeof(*share)); if(!share) { @@ -2837,7 +2837,7 @@ bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf, } if(!Curl_hash_add2(&multi->proto_hash, CURL_UNCONST(MPROTO_SCHANNEL_CERT_SHARE_KEY), - sizeof(MPROTO_SCHANNEL_CERT_SHARE_KEY) - 1, + CURL_CSTRLEN(MPROTO_SCHANNEL_CERT_SHARE_KEY), share, schannel_cert_share_free)) { curlx_free(share); curlx_free(CAfile); diff --git a/lib/vtls/schannel_verify.c b/lib/vtls/schannel_verify.c index e5fe2249a6..6e55c9b839 100644 --- a/lib/vtls/schannel_verify.c +++ b/lib/vtls/schannel_verify.c @@ -119,8 +119,8 @@ static CURLcode add_certs_data_to_store(HCERTSTORE trust_store, const char *ca_file_text, struct Curl_easy *data) { - const size_t begin_cert_len = strlen(BEGIN_CERT); - const size_t end_cert_len = strlen(END_CERT); + const size_t begin_cert_len = CURL_CSTRLEN(BEGIN_CERT); + const size_t end_cert_len = CURL_CSTRLEN(END_CERT); CURLcode result = CURLE_OK; int num_certs = 0; bool more_certs = 1; diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c index 2da004adba..952c5e5e71 100644 --- a/lib/vtls/vtls.c +++ b/lib/vtls/vtls.c @@ -483,8 +483,8 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data, pinned_hash = pinnedpubkey; while(pinned_hash && - !strncmp(pinned_hash, "sha256//", (sizeof("sha256//") - 1))) { - pinned_hash = pinned_hash + (sizeof("sha256//") - 1); + !strncmp(pinned_hash, "sha256//", CURL_CSTRLEN("sha256//"))) { + pinned_hash = pinned_hash + CURL_CSTRLEN("sha256//"); end_pos = strchr(pinned_hash, ';'); pinned_hash_len = end_pos ? (size_t)(end_pos - pinned_hash) : strlen(pinned_hash); diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c index e6ee960117..9fe0dc1c88 100644 --- a/lib/vtls/wolfssl.c +++ b/lib/vtls/wolfssl.c @@ -686,7 +686,7 @@ struct wssl_x509_share { static void wssl_x509_share_free(void *key, size_t key_len, void *p) { struct wssl_x509_share *share = p; - DEBUGASSERT(key_len == (sizeof(MPROTO_WSSL_X509_KEY) - 1)); + DEBUGASSERT(key_len == CURL_CSTRLEN(MPROTO_WSSL_X509_KEY)); DEBUGASSERT(!memcmp(MPROTO_WSSL_X509_KEY, key, key_len)); (void)key; (void)key_len; @@ -730,7 +730,7 @@ static WOLFSSL_X509_STORE *wssl_get_cached_x509_store(struct Curl_cfilter *cf, DEBUGASSERT(multi); share = multi ? Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_WSSL_X509_KEY), - sizeof(MPROTO_WSSL_X509_KEY) - 1) : NULL; + CURL_CSTRLEN(MPROTO_WSSL_X509_KEY)) : NULL; if(share && share->store && !wssl_cached_x509_store_expired(data, share) && !wssl_cached_x509_store_different(cf, share)) { @@ -753,7 +753,7 @@ static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, return; share = Curl_hash_pick(&multi->proto_hash, CURL_UNCONST(MPROTO_WSSL_X509_KEY), - sizeof(MPROTO_WSSL_X509_KEY) - 1); + CURL_CSTRLEN(MPROTO_WSSL_X509_KEY)); if(!share) { share = curlx_calloc(1, sizeof(*share)); @@ -761,7 +761,7 @@ static void wssl_set_cached_x509_store(struct Curl_cfilter *cf, return; if(!Curl_hash_add2(&multi->proto_hash, CURL_UNCONST(MPROTO_WSSL_X509_KEY), - sizeof(MPROTO_WSSL_X509_KEY) - 1, + CURL_CSTRLEN(MPROTO_WSSL_X509_KEY), share, wssl_x509_share_free)) { curlx_free(share); return; diff --git a/scripts/schemetable.c b/scripts/schemetable.c index 8127ecd2a1..67f6b81b14 100644 --- a/scripts/schemetable.c +++ b/scripts/schemetable.c @@ -29,7 +29,7 @@ * function in url.c. */ -static const char *scheme[] = { +static const char * const scheme[] = { "dict", "file", "ftp", diff --git a/src/curlinfo.c b/src/curlinfo.c index 36eabeb78f..8b4659200f 100644 --- a/src/curlinfo.c +++ b/src/curlinfo.c @@ -43,7 +43,7 @@ #include /* for OPENSSL_NO_OCSP */ #endif -static const char *disabled[] = { +static const char * const disabled[] = { "bindlocal: " #ifdef CURL_DISABLE_BINDLOCAL "OFF" diff --git a/src/tool_doswin.c b/src/tool_doswin.c index a64665bcd9..52eb69bd69 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -145,13 +145,13 @@ static SANITIZEcode msdosify(char ** const sanitized, const char *file_name, static const char illegal_chars_dos[] = ".+, ;=[]" /* illegal in DOS */ "|<>/\\\":?*"; /* illegal in DOS & W95 */ - static const char *illegal_chars_w95 = &illegal_chars_dos[8]; + static const char * const illegal_chars_w95 = &illegal_chars_dos[8]; int idx, dot_idx; const char *s = file_name; char *d = dos_name; - const char * const dlimit = dos_name + sizeof(dos_name) - 1; + const char * const dlimit = dos_name + CURL_CSTRLEN(dos_name); const char *illegal_aliens = illegal_chars_dos; - size_t len = sizeof(illegal_chars_dos) - 1; + size_t len = CURL_CSTRLEN(illegal_chars_dos); if(!sanitized) return SANITIZE_ERR_BAD_ARGUMENT; diff --git a/src/tool_easysrc.c b/src/tool_easysrc.c index 5b3c6cb45b..c2a34c3b2b 100644 --- a/src/tool_easysrc.c +++ b/src/tool_easysrc.c @@ -64,7 +64,7 @@ static const char * const srchard[] = { "", NULL }; -static const char *const srcend[] = { +static const char * const srcend[] = { "", " return (int)result;", "}", diff --git a/src/tool_formparse.c b/src/tool_formparse.c index 6d41711a40..450a2b3a99 100644 --- a/src/tool_formparse.c +++ b/src/tool_formparse.c @@ -509,7 +509,7 @@ static void param_type(char **ptr, char **ptype, char **endct, char *sep) { char *p = *ptr; size_t tlen; - for(p += sizeof("type=") - 1; ISBLANK(*p); p++) + for(p += CURL_CSTRLEN("type="); ISBLANK(*p); p++) ; /* set type pointer */ *ptype = p; @@ -533,7 +533,7 @@ static void param_filename(char **ptr, char **endct, char **pfilename, **endct = '\0'; *endct = NULL; } - for(p += sizeof("filename=") - 1; ISBLANK(*p); p++) + for(p += CURL_CSTRLEN("filename="); ISBLANK(*p); p++) ; tp = p; *pfilename = get_param_word(&p, &endpos, endchar); @@ -557,7 +557,7 @@ static int param_headers(char **ptr, char **endct, **endct = '\0'; *endct = NULL; } - p += sizeof("headers=") - 1; + p += CURL_CSTRLEN("headers="); if(*p == '@' || *p == '<') { char *hdrfile; FILE *fp; @@ -623,7 +623,7 @@ static void param_encoder(char **ptr, char **endct, char **pencoder, **endct = '\0'; *endct = NULL; } - for(p += sizeof("encoder=") - 1; ISBLANK(*p); p++) + for(p += CURL_CSTRLEN("encoder="); ISBLANK(*p); p++) ; tp = p; *pencoder = get_param_word(&p, &endpos, endchar); diff --git a/src/tool_getparam.c b/src/tool_getparam.c index 479168e0bd..73419ead09 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -2488,7 +2488,7 @@ static ParameterError opt_string(struct OperationConfig *config, { ParameterError err = PARAM_OK; curl_off_t value; - static const char *redir_protos[] = { + static const char * const redir_protos[] = { "http", "https", "ftp", diff --git a/src/tool_helpers.c b/src/tool_helpers.c index b5e9b54121..1b998d2ca6 100644 --- a/src/tool_helpers.c +++ b/src/tool_helpers.c @@ -77,7 +77,7 @@ const char *param2text(ParameterError error) int SetHTTPrequest(HttpReq req, HttpReq *store) { /* this mirrors the HttpReq enum in tool_sdecls.h */ - const char *reqname[] = { + static const char * const reqname[] = { "", /* unspec */ "GET (-G, --get)", "HEAD (-I, --head)", @@ -101,7 +101,7 @@ int SetHTTPrequest(HttpReq req, HttpReq *store) void customrequest_helper(HttpReq req, const char *method) { /* this mirrors the HttpReq enum in tool_sdecls.h */ - const char *dflt[] = { + static const char * const dflt[] = { "GET", "GET", "HEAD", diff --git a/src/tool_libinfo.c b/src/tool_libinfo.c index bce6bb7d6e..dfb23912f3 100644 --- a/src/tool_libinfo.c +++ b/src/tool_libinfo.c @@ -27,7 +27,7 @@ /* global variable definitions, for libcurl runtime info */ -static const char *no_protos = NULL; +static const char * const no_protos = NULL; curl_version_info_data *curlinfo = NULL; const char * const *built_in_protos = &no_protos; diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 57a49ef97f..a3be2afcf7 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -297,7 +297,7 @@ ParameterError secs2ms(long *val, const char *str) { curl_off_t secs; long ms = 0; - const unsigned int digs[] = { + static const unsigned int digs[] = { 1, 10, 100, diff --git a/src/tool_progress.c b/src/tool_progress.c index c30644c0e3..d3ee694fea 100644 --- a/src/tool_progress.c +++ b/src/tool_progress.c @@ -35,7 +35,7 @@ UNITTEST char *max5data(curl_off_t bytes, char *max5, size_t mlen) { /* a signed 64-bit value is 8192 petabytes maximum */ - const char unit[] = { 'k', 'M', 'G', 'T', 'P', 'E', 0 }; + static const char unit[] = { 'k', 'M', 'G', 'T', 'P', 'E', 0 }; int k = 0; if(bytes < 100000) { curl_msnprintf(max5, mlen, "%5" CURL_FORMAT_CURL_OFF_T, bytes); diff --git a/src/var.c b/src/var.c index 8f9dbbb5b0..464b0c1c2c 100644 --- a/src/var.c +++ b/src/var.c @@ -62,15 +62,15 @@ static const struct tool_var *varcontent(const char *name, size_t nlen) (!strncmp(ptr, name, len) && ENDOFFUNC((ptr)[len])) #define FUNC_TRIM "trim" -#define FUNC_TRIM_LEN (sizeof(FUNC_TRIM) - 1) +#define FUNC_TRIM_LEN CURL_CSTRLEN(FUNC_TRIM) #define FUNC_JSON "json" -#define FUNC_JSON_LEN (sizeof(FUNC_JSON) - 1) +#define FUNC_JSON_LEN CURL_CSTRLEN(FUNC_JSON) #define FUNC_URL "url" -#define FUNC_URL_LEN (sizeof(FUNC_URL) - 1) +#define FUNC_URL_LEN CURL_CSTRLEN(FUNC_URL) #define FUNC_B64 "b64" -#define FUNC_B64_LEN (sizeof(FUNC_B64) - 1) +#define FUNC_B64_LEN CURL_CSTRLEN(FUNC_B64) #define FUNC_64DEC "64dec" /* base64 decode */ -#define FUNC_64DEC_LEN (sizeof(FUNC_64DEC) - 1) +#define FUNC_64DEC_LEN CURL_CSTRLEN(FUNC_64DEC) static ParameterError varfunc(char *c, /* content */ size_t clen, /* content length */ diff --git a/tests/http/testenv/mod_curltest/mod_curltest.c b/tests/http/testenv/mod_curltest/mod_curltest.c index 0bb0c78a36..d783af1ab6 100644 --- a/tests/http/testenv/mod_curltest/mod_curltest.c +++ b/tests/http/testenv/mod_curltest/mod_curltest.c @@ -949,7 +949,7 @@ static int curltest_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { void *data = NULL; - const char *key = "mod_curltest_init_counter"; + static const char *key = "mod_curltest_init_counter"; (void)p; (void)plog; diff --git a/tests/libtest/lib1514.c b/tests/libtest/lib1514.c index a799e7668d..528468eee0 100644 --- a/tests/libtest/lib1514.c +++ b/tests/libtest/lib1514.c @@ -29,7 +29,7 @@ #include "first.h" struct t1514_WriteThis { - char *readptr; + const char *readptr; size_t sizeleft; }; @@ -55,9 +55,9 @@ static CURLcode test_lib1514(const char *URL) CURL *curl; CURLcode result = CURLE_OK; - static char testdata[] = "dummy"; + static const char testdata[] = "dummy"; - struct t1514_WriteThis pooh = { testdata, sizeof(testdata) - 1 }; + struct t1514_WriteThis pooh = { testdata, CURL_CSTRLEN(testdata) }; global_init(CURL_GLOBAL_ALL); diff --git a/tests/libtest/lib1517.c b/tests/libtest/lib1517.c index 30e80a7bce..a88705ed68 100644 --- a/tests/libtest/lib1517.c +++ b/tests/libtest/lib1517.c @@ -60,7 +60,7 @@ static CURLcode test_lib1517(const char *URL) struct t1517_WriteThis pooh; pooh.readptr = testdata; - pooh.sizeleft = sizeof(testdata) - 1; + pooh.sizeleft = CURL_CSTRLEN(testdata); if(curl_global_init(CURL_GLOBAL_ALL)) { curl_mfprintf(stderr, "curl_global_init() failed\n"); diff --git a/tests/libtest/lib1520.c b/tests/libtest/lib1520.c index 9ed257591e..b97fd94fc8 100644 --- a/tests/libtest/lib1520.c +++ b/tests/libtest/lib1520.c @@ -29,7 +29,7 @@ struct upload_status { static size_t t1520_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) { - static const char *payload_text[] = { + static const char * const payload_text[] = { "From: different\r\n", "To: another\r\n", "\r\n", diff --git a/tests/libtest/lib1525.c b/tests/libtest/lib1525.c index 3498941ea2..7465eb59dd 100644 --- a/tests/libtest/lib1525.c +++ b/tests/libtest/lib1525.c @@ -31,7 +31,7 @@ #include "first.h" static const char t1525_data[] = "Hello Cloud!\n"; -static size_t const t1525_datalen = sizeof(t1525_data) - 1; +static const size_t t1525_datalen = CURL_CSTRLEN(t1525_data); static size_t t1525_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) { diff --git a/tests/libtest/lib1526.c b/tests/libtest/lib1526.c index 6e01804628..56b1b749b3 100644 --- a/tests/libtest/lib1526.c +++ b/tests/libtest/lib1526.c @@ -30,7 +30,7 @@ #include "first.h" static const char t1526_data[] = "Hello Cloud!\n"; -static size_t const t1526_datalen = sizeof(t1526_data) - 1; +static const size_t t1526_datalen = CURL_CSTRLEN(t1526_data); static size_t t1526_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) { diff --git a/tests/libtest/lib1527.c b/tests/libtest/lib1527.c index ef438dc901..1caa37d8d3 100644 --- a/tests/libtest/lib1527.c +++ b/tests/libtest/lib1527.c @@ -30,7 +30,7 @@ #include "first.h" static const char t1527_data[] = "Hello Cloud!\n"; -static size_t const t1527_datalen = sizeof(t1527_data) - 1; +static const size_t t1527_datalen = CURL_CSTRLEN(t1527_data); static size_t t1527_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) { diff --git a/tests/libtest/lib1531.c b/tests/libtest/lib1531.c index def737f9f1..20ac3639eb 100644 --- a/tests/libtest/lib1531.c +++ b/tests/libtest/lib1531.c @@ -25,8 +25,8 @@ static CURLcode test_lib1531(const char *URL) { - static char const testdata[] = ".abc\0xyz"; - static curl_off_t const testdatalen = sizeof(testdata) - 1; + static const char testdata[] = ".abc\0xyz"; + static const curl_off_t testdatalen = CURL_CSTRLEN(testdata); CURL *curl; CURLM *multi; diff --git a/tests/libtest/lib1537.c b/tests/libtest/lib1537.c index 1ef0be9c75..7fd91f9d4f 100644 --- a/tests/libtest/lib1537.c +++ b/tests/libtest/lib1537.c @@ -25,8 +25,10 @@ static CURLcode test_lib1537(const char *URL) { - const unsigned char a[] = { 0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7 }; + static const unsigned char a[] = { + 0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7 + }; CURLcode result = CURLE_OK; char *ptr = NULL; int asize; diff --git a/tests/libtest/lib1554.c b/tests/libtest/lib1554.c index 8b37374c5a..c553095c61 100644 --- a/tests/libtest/lib1554.c +++ b/tests/libtest/lib1554.c @@ -23,7 +23,7 @@ ***************************************************************************/ #include "first.h" -static const char *ldata_names[] = { +static const char * const ldata_names[] = { "NONE", "SHARE", "COOKIE", diff --git a/tests/libtest/lib1560.c b/tests/libtest/lib1560.c index 1c8aabfd5b..fafdd8de99 100644 --- a/tests/libtest/lib1560.c +++ b/tests/libtest/lib1560.c @@ -2269,7 +2269,7 @@ static char bigpart[120000]; */ static int huge(void) { - static const char *smallpart = "c"; + static const char smallpart[] = "c"; int i; CURLU *urlp = curl_url(); CURLUcode rc; @@ -2323,7 +2323,7 @@ static int huge(void) static int urldup(void) { - static const char *url[] = { + static const char * const url[] = { "http://" "user:pwd@" "[2a04:4e42:e00::347%25eth0]" diff --git a/tests/libtest/lib1576.c b/tests/libtest/lib1576.c index 64aaa4c5ea..a052519a25 100644 --- a/tests/libtest/lib1576.c +++ b/tests/libtest/lib1576.c @@ -23,8 +23,9 @@ ***************************************************************************/ #include "first.h" -static char t1576_data[] = "request indicates that the client, which made"; -static size_t const t1576_datalen = sizeof(t1576_data) - 1; +static const char t1576_data[] = "request indicates that the client, " + "which made"; +static const size_t t1576_datalen = CURL_CSTRLEN(t1576_data); static size_t t1576_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) { diff --git a/tests/libtest/lib1591.c b/tests/libtest/lib1591.c index 97b234234f..427f966564 100644 --- a/tests/libtest/lib1591.c +++ b/tests/libtest/lib1591.c @@ -34,7 +34,7 @@ static size_t consumed = 0; static size_t t1591_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) { static const char testdata[] = "Hello Cloud!\r\n"; - static size_t const datalen = sizeof(testdata) - 1; + static const size_t datalen = CURL_CSTRLEN(testdata); size_t amount = nmemb * size; /* Total bytes curl wants */ diff --git a/tests/libtest/lib1598.c b/tests/libtest/lib1598.c index 961c424e68..106a339c07 100644 --- a/tests/libtest/lib1598.c +++ b/tests/libtest/lib1598.c @@ -52,7 +52,7 @@ static int t1598_trailers_callback(struct curl_slist **list, void *userdata) static CURLcode test_lib1598(const char *URL) { - static const char *post_data = "xxx=yyy&aaa=bbbbb"; + static const char post_data[] = "xxx=yyy&aaa=bbbbb"; CURL *curl = NULL; CURLcode result = CURLE_FAILED_INIT; @@ -84,7 +84,7 @@ static CURLcode test_lib1598(const char *URL) easy_setopt(curl, CURLOPT_URL, URL); easy_setopt(curl, CURLOPT_HTTPHEADER, hhl); - easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(post_data)); + easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)CURL_CSTRLEN(post_data)); easy_setopt(curl, CURLOPT_POSTFIELDS, post_data); easy_setopt(curl, CURLOPT_TRAILERFUNCTION, t1598_trailers_callback); easy_setopt(curl, CURLOPT_TRAILERDATA, NULL); diff --git a/tests/libtest/lib1662.c b/tests/libtest/lib1662.c index 0e4942e9ad..4c338d2921 100644 --- a/tests/libtest/lib1662.c +++ b/tests/libtest/lib1662.c @@ -30,7 +30,7 @@ struct t1662_WriteThis { static size_t t1662_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) { static const char testdata[] = "mooaaa"; - static size_t const testdatalen = sizeof(testdata) - 1; + static const size_t testdatalen = CURL_CSTRLEN(testdata); struct t1662_WriteThis *pooh = (struct t1662_WriteThis *)userp; diff --git a/tests/libtest/lib1901.c b/tests/libtest/lib1901.c index a6ccbdb0cb..dae52a7f2c 100644 --- a/tests/libtest/lib1901.c +++ b/tests/libtest/lib1901.c @@ -25,7 +25,7 @@ static size_t t1901_read_cb(char *ptr, size_t size, size_t nmemb, void *stream) { - static const char *chunks[] = { "one", "two", "three", "four", NULL }; + static const char * const chunks[] = { "one", "two", "three", "four", NULL }; static int ix = 0; (void)stream; if(chunks[ix]) { diff --git a/tests/libtest/lib1940.c b/tests/libtest/lib1940.c index 349d8131c6..a0fea9264f 100644 --- a/tests/libtest/lib1940.c +++ b/tests/libtest/lib1940.c @@ -25,7 +25,7 @@ static void t1940_showem(CURL *curl, int header_request, unsigned int type) { - static const char *testdata[] = { + static const char * const testdata[] = { "daTE", "Server", "content-type", diff --git a/tests/libtest/lib1948.c b/tests/libtest/lib1948.c index 9b8217be8f..73bd5d7ba0 100644 --- a/tests/libtest/lib1948.c +++ b/tests/libtest/lib1948.c @@ -55,9 +55,9 @@ static CURLcode test_lib1948(const char *URL) easy_setopt(curl, CURLOPT_HEADER, 1L); easy_setopt(curl, CURLOPT_READFUNCTION, put_callback); pbuf.buf = testput; - pbuf.len = sizeof(testput) - 1; + pbuf.len = CURL_CSTRLEN(testput); easy_setopt(curl, CURLOPT_READDATA, &pbuf); - easy_setopt(curl, CURLOPT_INFILESIZE, (long)(sizeof(testput) - 1)); + easy_setopt(curl, CURLOPT_INFILESIZE, (long)CURL_CSTRLEN(testput)); easy_setopt(curl, CURLOPT_URL, URL); result = curl_easy_perform(curl); if(result) @@ -66,7 +66,7 @@ static CURLcode test_lib1948(const char *URL) /* POST */ easy_setopt(curl, CURLOPT_POST, 1L); easy_setopt(curl, CURLOPT_POSTFIELDS, testput); - easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)(sizeof(testput) - 1)); + easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)CURL_CSTRLEN(testput)); result = curl_easy_perform(curl); test_cleanup: diff --git a/tests/libtest/lib1965.c b/tests/libtest/lib1965.c index e09ff349b3..683e5a716a 100644 --- a/tests/libtest/lib1965.c +++ b/tests/libtest/lib1965.c @@ -27,7 +27,7 @@ static CURLcode test_lib1965(const char *URL) { CURLcode result = CURLE_OK; CURLUcode rc; - static const char *schemes[] = { + static const char * const schemes[] = { "bad!", "bad{", "bad/", "bad\\", "a!", "a+123", "http-2", "http.1", "a+-.123", "http-+++2", "http.1--", diff --git a/tests/libtest/lib3102.c b/tests/libtest/lib3102.c index 59db9e45f1..312d5e600e 100644 --- a/tests/libtest/lib3102.c +++ b/tests/libtest/lib3102.c @@ -47,11 +47,11 @@ static bool is_chain_in_order(struct curl_certinfo *cert_info) static const char issuer_prefix[] = "Issuer:"; static const char subject_prefix[] = "Subject:"; - if(!strncmp(slist->data, issuer_prefix, sizeof(issuer_prefix) - 1)) { - issuer = slist->data + sizeof(issuer_prefix) - 1; + if(!strncmp(slist->data, issuer_prefix, CURL_CSTRLEN(issuer_prefix))) { + issuer = slist->data + CURL_CSTRLEN(issuer_prefix); } - if(!strncmp(slist->data, subject_prefix, sizeof(subject_prefix) - 1)) { - subject = slist->data + sizeof(subject_prefix) - 1; + if(!strncmp(slist->data, subject_prefix, CURL_CSTRLEN(subject_prefix))) { + subject = slist->data + CURL_CSTRLEN(subject_prefix); } } diff --git a/tests/libtest/lib505.c b/tests/libtest/lib505.c index 7abaacd14e..bf1310fcd2 100644 --- a/tests/libtest/lib505.c +++ b/tests/libtest/lib505.c @@ -41,8 +41,8 @@ static CURLcode test_lib505(const char *URL) struct curl_slist *headerlist; struct curl_slist *temp; - static const char *buf_1 = "RNFR 505"; - static const char *buf_2 = "RNTO 505-forreal"; + static const char buf_1[] = "RNFR 505"; + static const char buf_2[] = "RNTO 505-forreal"; if(!libtest_arg2) { curl_mfprintf(stderr, "Usage: \n"); diff --git a/tests/libtest/lib508.c b/tests/libtest/lib508.c index 7ecf2665c4..20aa1ff865 100644 --- a/tests/libtest/lib508.c +++ b/tests/libtest/lib508.c @@ -56,7 +56,7 @@ static CURLcode test_lib508(const char *URL) struct t508_WriteThis pooh; pooh.readptr = testdata; - pooh.sizeleft = sizeof(testdata) - 1; + pooh.sizeleft = CURL_CSTRLEN(testdata); if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { curl_mfprintf(stderr, "curl_global_init() failed\n"); diff --git a/tests/libtest/lib536.c b/tests/libtest/lib536.c index e25922062a..d6347545f5 100644 --- a/tests/libtest/lib536.c +++ b/tests/libtest/lib536.c @@ -37,7 +37,7 @@ static CURLcode test_lib536(const char *URL) CURL *curl; struct curl_slist *host = NULL; - static const char *url_with_proxy = "http://usingproxy.test/"; + static const char url_with_proxy[] = "http://usingproxy.test/"; const char *url_without_proxy = libtest_arg2; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { diff --git a/tests/libtest/lib544.c b/tests/libtest/lib544.c index 02dc11f39b..013c2ab32b 100644 --- a/tests/libtest/lib544.c +++ b/tests/libtest/lib544.c @@ -63,7 +63,7 @@ static CURLcode test_lib544(const char *URL) easy_setopt(curl, CURLOPT_HEADER, 1L); /* include header */ /* Update the original data to detect non-copy. */ - curlx_strcopy(teststring, sizeof(teststring), "FAIL", strlen("FAIL")); + curlx_strcopy(teststring, sizeof(teststring), "FAIL", CURL_CSTRLEN("FAIL")); { CURL *curl2; diff --git a/tests/libtest/lib547.c b/tests/libtest/lib547.c index e44c16b55b..66ad32afbb 100644 --- a/tests/libtest/lib547.c +++ b/tests/libtest/lib547.c @@ -29,7 +29,7 @@ #include "first.h" static const char t547_uploadthis[] = "this is the blurb we want to upload\n"; -static size_t const t547_datalen = sizeof(t547_uploadthis) - 1; +static const size_t t547_datalen = CURL_CSTRLEN(t547_uploadthis); static size_t t547_read_cb(char *ptr, size_t size, size_t nmemb, void *clientp) { diff --git a/tests/libtest/lib554.c b/tests/libtest/lib554.c index 98a7ba7fdc..ce4348a8d7 100644 --- a/tests/libtest/lib554.c +++ b/tests/libtest/lib554.c @@ -69,7 +69,7 @@ static CURLcode t554_test_once(const char *URL, bool oldstyle) struct t554_WriteThis pooh2; pooh.readptr = testdata; - pooh.sizeleft = sizeof(testdata) - 1; + pooh.sizeleft = CURL_CSTRLEN(testdata); /* Fill in the file upload field */ if(oldstyle) { @@ -99,7 +99,7 @@ static CURLcode t554_test_once(const char *URL, bool oldstyle) a file upload but still using the callback */ pooh2.readptr = testdata; - pooh2.sizeleft = sizeof(testdata) - 1; + pooh2.sizeleft = CURL_CSTRLEN(testdata); /* Fill in the file upload field */ formrc = curl_formadd(&formpost, diff --git a/tests/libtest/lib555.c b/tests/libtest/lib555.c index 9e11aae7d7..e2cdfbc971 100644 --- a/tests/libtest/lib555.c +++ b/tests/libtest/lib555.c @@ -33,7 +33,7 @@ #include "first.h" static const char t555_uploadthis[] = "this is the blurb we want to upload\n"; -static size_t const t555_datalen = sizeof(t555_uploadthis) - 1; +static const size_t t555_datalen = CURL_CSTRLEN(t555_uploadthis); static size_t t555_read_cb(char *ptr, size_t size, size_t nmemb, void *clientp) { diff --git a/tests/libtest/lib571.c b/tests/libtest/lib571.c index 37b93e5390..4f506bc3b9 100644 --- a/tests/libtest/lib571.c +++ b/tests/libtest/lib571.c @@ -44,7 +44,7 @@ static int rtp_packet_count = 0; static size_t rtp_write(char *data, size_t size, size_t nmemb, void *stream) { - static const char *RTP_DATA = "$_1234\n\0Rsdf"; + static const char RTP_DATA[] = "$_1234\n\0Rsdf"; int channel = RTP_PKT_CHANNEL(data); int message_size; diff --git a/tests/libtest/lib643.c b/tests/libtest/lib643.c index eaf75e8fe1..c2aed4f0d2 100644 --- a/tests/libtest/lib643.c +++ b/tests/libtest/lib643.c @@ -69,7 +69,7 @@ static CURLcode t643_test_once(const char *URL, bool oldstyle) pooh.readptr = testdata; if(testnum == 643) - datasize = (curl_off_t)(sizeof(testdata) - 1); + datasize = (curl_off_t)CURL_CSTRLEN(testdata); pooh.sizeleft = datasize; curl = curl_easy_init(); @@ -123,7 +123,7 @@ static CURLcode t643_test_once(const char *URL, bool oldstyle) pooh2.readptr = testdata; if(testnum == 643) - datasize = (curl_off_t)(sizeof(testdata) - 1); + datasize = (curl_off_t)CURL_CSTRLEN(testdata); pooh2.sizeleft = datasize; part = curl_mime_addpart(mime); diff --git a/tests/libtest/lib654.c b/tests/libtest/lib654.c index 0494d580ab..a10dc94478 100644 --- a/tests/libtest/lib654.c +++ b/tests/libtest/lib654.c @@ -92,7 +92,7 @@ static CURLcode test_lib654(const char *URL) /* Prepare the callback structure. */ pooh.readptr = testdata; - pooh.sizeleft = (curl_off_t)(sizeof(testdata) - 1); + pooh.sizeleft = (curl_off_t)CURL_CSTRLEN(testdata); pooh.freecount = 0; /* Build the mime tree. */ diff --git a/tests/libtest/lib655.c b/tests/libtest/lib655.c index 3dd70dfa73..5e1f0990e2 100644 --- a/tests/libtest/lib655.c +++ b/tests/libtest/lib655.c @@ -25,7 +25,7 @@ #include "testtrace.h" -static const char *TEST_DATA_STRING = "Test data"; +static const char TEST_DATA_STRING[] = "Test data"; static int cb_count = 0; static int resolver_alloc_cb_fail(void *resolver_state, void *reserved, diff --git a/tests/libtest/lib667.c b/tests/libtest/lib667.c index 28a9cde6d2..38158dc2b4 100644 --- a/tests/libtest/lib667.c +++ b/tests/libtest/lib667.c @@ -82,7 +82,7 @@ static CURLcode test_lib667(const char *URL) /* Prepare the callback structure. */ pooh.readptr = testdata; - pooh.sizeleft = (curl_off_t)(sizeof(testdata) - 1); + pooh.sizeleft = (curl_off_t)CURL_CSTRLEN(testdata); /* Build the mime tree. */ mime = curl_mime_init(curl); diff --git a/tests/libtest/lib668.c b/tests/libtest/lib668.c index cd9897f7e9..fd59a0c3f9 100644 --- a/tests/libtest/lib668.c +++ b/tests/libtest/lib668.c @@ -77,7 +77,7 @@ static CURLcode test_lib668(const char *URL) /* Prepare the callback structures. */ pooh1.readptr = testdata; - pooh1.sizeleft = sizeof(testdata) - 1; + pooh1.sizeleft = CURL_CSTRLEN(testdata); pooh2 = pooh1; /* Build the mime tree. */ diff --git a/tests/libtest/lib677.c b/tests/libtest/lib677.c index 106fbb2603..6a6c5ef5a9 100644 --- a/tests/libtest/lib677.c +++ b/tests/libtest/lib677.c @@ -77,8 +77,8 @@ static CURLcode test_lib677(const char *URL) if(!state) { CURLcode ec; - ec = curl_easy_send(curl, testcmd + pos, - sizeof(testcmd) - 1 - pos, &len); + ec = curl_easy_send(curl, testcmd + pos, CURL_CSTRLEN(testcmd) - pos, + &len); if(ec == CURLE_AGAIN) { continue; } @@ -92,7 +92,7 @@ static CURLcode test_lib677(const char *URL) pos += len; else pos = 0; - if(pos == sizeof(testcmd) - 1) { + if(pos == CURL_CSTRLEN(testcmd)) { state++; pos = 0; } diff --git a/tests/libtest/lib757.c b/tests/libtest/lib757.c index 325f3b7b6b..378c78cf81 100644 --- a/tests/libtest/lib757.c +++ b/tests/libtest/lib757.c @@ -24,7 +24,7 @@ #include "first.h" static const char t757_data[] = "fun-times"; -static size_t const t757_datalen = sizeof(t757_data) - 1; +static const size_t t757_datalen = CURL_CSTRLEN(t757_data); static size_t read_757(char *buffer, size_t size, size_t nitems, void *arg) { diff --git a/tests/server/mqttd.c b/tests/server/mqttd.c index 189ac41bec..732bcd2efb 100644 --- a/tests/server/mqttd.c +++ b/tests/server/mqttd.c @@ -178,8 +178,8 @@ static int connack(FILE *dump, curl_socket_t fd) MQTT_MSG_CONNACK, 0x02, 0x00, 0x00 }; - ssize_t rc; const char *label = "CONNACK"; + ssize_t rc; if(m_config.pingresp_as_connack) { /* Send a PINGRESP (0xD0) with remaining_length=2 and payload @@ -260,8 +260,8 @@ static int disconnect(FILE *dump, curl_socket_t fd) MQTT_MSG_DISCONNECT, 0x00, 0x00, 0x00 /* extra bytes for malformed variant */ }; - size_t pktlen = 2; const char *label = "DISCONNECT"; + size_t pktlen = 2; ssize_t rc; if(m_config.disconnect_malformed) { @@ -638,8 +638,8 @@ static curl_socket_t mqttit(curl_socket_t fd) } } else { - const char *def = "this is random payload yes yes it is"; - publish(dump, fd, packet_id, topic, def, strlen(def)); + static const char def[] = "this is random payload yes yes it is"; + publish(dump, fd, packet_id, topic, def, CURL_CSTRLEN(def)); } disconnect(dump, fd); } diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c index fe2dded9fa..7e6c8ef43b 100644 --- a/tests/server/rtspd.c +++ b/tests/server/rtspd.c @@ -106,18 +106,18 @@ struct rtspd_httprequest { #define END_OF_HEADERS "\r\n\r\n" /* sent as reply to a QUIT */ -static const char *docquit_rtsp = "HTTP/1.1 200 Goodbye" END_OF_HEADERS; +static const char docquit_rtsp[] = "HTTP/1.1 200 Goodbye" END_OF_HEADERS; /* sent as reply to a CONNECT */ -static const char *docconnect = +static const char docconnect[] = "HTTP/1.1 200 Mighty fine indeed" END_OF_HEADERS; /* sent as reply to a "bad" CONNECT */ -static const char *docbadconnect = +static const char docbadconnect[] = "HTTP/1.1 501 Forbidden you fool" END_OF_HEADERS; /* send back this on HTTP 404 file not found */ -static const char *doc404_HTTP = +static const char doc404_HTTP[] = "HTTP/1.1 404 Not Found\r\n" "Server: " RTSPDVERSION "\r\n" "Connection: close\r\n" @@ -133,13 +133,13 @@ static const char *doc404_HTTP = "\n"; /* send back this on RTSP 404 file not found */ -static const char *doc404_RTSP = "RTSP/1.0 404 Not Found\r\n" +static const char doc404_RTSP[] = "RTSP/1.0 404 Not Found\r\n" "Server: " RTSPDVERSION END_OF_HEADERS; /* Default size to send away fake RTP data */ #define RTP_DATA_SIZE 12 -static const char *RTP_DATA = "$_1234\n\0Rsdf"; +static const char RTP_DATA[] = "$_1234\n\0Rsdf"; static int rtspd_ProcessRequest(struct rtspd_httprequest *req) { @@ -267,16 +267,17 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) logmsg("Found a reply-servercmd section!"); do { rtp_size_err = 0; - if(!strncmp(CMD_AUTH_REQUIRED, ptr, strlen(CMD_AUTH_REQUIRED))) { + if(!strncmp(CMD_AUTH_REQUIRED, ptr, + CURL_CSTRLEN(CMD_AUTH_REQUIRED))) { logmsg("instructed to require authorization header"); req->auth_req = TRUE; } - else if(!strncmp(CMD_IDLE, ptr, strlen(CMD_IDLE))) { + else if(!strncmp(CMD_IDLE, ptr, CURL_CSTRLEN(CMD_IDLE))) { logmsg("instructed to idle"); req->rcmd = RCMD_IDLE; req->open = TRUE; } - else if(!strncmp(CMD_STREAM, ptr, strlen(CMD_STREAM))) { + else if(!strncmp(CMD_STREAM, ptr, CURL_CSTRLEN(CMD_STREAM))) { logmsg("instructed to stream"); req->rcmd = RCMD_STREAM; } @@ -404,7 +405,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) if(req->pipe) /* we do have a full set, advance the checkindex to after the end of the headers, for the pipelining case mostly */ - req->checkindex += (end - line) + strlen(END_OF_HEADERS); + req->checkindex += (end - line) + CURL_CSTRLEN(END_OF_HEADERS); /* **** Persistence **** * @@ -427,7 +428,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) ignore the content-length, we return as soon as all headers have been received */ curl_off_t clen; - const char *p = line + strlen("Content-Length:"); + const char *p = line + CURL_CSTRLEN("Content-Length:"); if(curlx_str_numblanks(&p, &clen)) { /* this assumes that a zero Content-Length is valid */ logmsg("Found invalid '%s' in the request", line); @@ -442,7 +443,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) break; } else if(!CURL_STRNICMP("Transfer-Encoding: chunked", line, - strlen("Transfer-Encoding: chunked"))) { + CURL_CSTRLEN("Transfer-Encoding: chunked"))) { /* chunked data coming in */ chunked = TRUE; } @@ -506,12 +507,12 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) if(!req->pipe && req->open && req->prot_version >= 11 && - req->reqbuf + req->offset > end + strlen(END_OF_HEADERS) && - (!strncmp(req->reqbuf, "GET", strlen("GET")) || - !strncmp(req->reqbuf, "HEAD", strlen("HEAD")))) { + req->reqbuf + req->offset > end + CURL_CSTRLEN(END_OF_HEADERS) && + (!strncmp(req->reqbuf, "GET", CURL_CSTRLEN("GET")) || + !strncmp(req->reqbuf, "HEAD", CURL_CSTRLEN("HEAD")))) { /* If we have a persistent connection, HTTP version >= 1.1 and GET/HEAD request, enable pipelining. */ - req->checkindex = (end - req->reqbuf) + strlen(END_OF_HEADERS); + req->checkindex = (end - req->reqbuf) + CURL_CSTRLEN(END_OF_HEADERS); req->pipelining = TRUE; } @@ -523,7 +524,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) end = strstr(line, END_OF_HEADERS); if(!end) break; - req->checkindex += (end - line) + strlen(END_OF_HEADERS); + req->checkindex += (end - line) + CURL_CSTRLEN(END_OF_HEADERS); req->pipe--; } @@ -535,7 +536,8 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) return 1; /* done */ if(req->cl > 0) { - if(req->cl <= req->offset - (end - req->reqbuf) - strlen(END_OF_HEADERS)) + if(req->cl <= req->offset - (end - req->reqbuf) - + CURL_CSTRLEN(END_OF_HEADERS)) return 1; /* done */ else return 0; /* not complete yet */ diff --git a/tests/server/socksd.c b/tests/server/socksd.c index b0b5b6771c..4de563b06c 100644 --- a/tests/server/socksd.c +++ b/tests/server/socksd.c @@ -102,9 +102,9 @@ static void socksd_resetdefaults(void) curlx_strcopy(s_config.addr, sizeof(s_config.addr), CONFIG_ADDR, strlen(CONFIG_ADDR)); curlx_strcopy(s_config.user, sizeof(s_config.user), - "user", strlen("user")); + "user", CURL_CSTRLEN("user")); curlx_strcopy(s_config.password, sizeof(s_config.password), - "password", strlen("password")); + "password", CURL_CSTRLEN("password")); } static void socksd_getconfig(void) diff --git a/tests/server/sws.c b/tests/server/sws.c index 8190002af2..e47ba7fc3d 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -141,10 +141,10 @@ static const char *cmdfile = "log/server.cmd"; static const char *end_of_headers = END_OF_HEADERS; /* sent as reply to a QUIT */ -static const char *docquit_sws = "HTTP/1.1 200 Goodbye" END_OF_HEADERS; +static const char docquit_sws[] = "HTTP/1.1 200 Goodbye" END_OF_HEADERS; /* send back this on 404 file not found */ -static const char *doc404 = +static const char doc404[] = "HTTP/1.1 404 Not Found\r\n" "Server: " SWSVERSION "\r\n" "Connection: close\r\n" @@ -262,29 +262,29 @@ static int sws_parse_servercmd(struct sws_httprequest *req) while(cmd && cmdsize) { const char *check; - if(!strncmp(CMD_AUTH_REQUIRED, cmd, strlen(CMD_AUTH_REQUIRED))) { + if(!strncmp(CMD_AUTH_REQUIRED, cmd, CURL_CSTRLEN(CMD_AUTH_REQUIRED))) { logmsg("instructed to require authorization header"); req->auth_req = TRUE; } - else if(!strncmp(CMD_IDLE, cmd, strlen(CMD_IDLE))) { + else if(!strncmp(CMD_IDLE, cmd, CURL_CSTRLEN(CMD_IDLE))) { logmsg("instructed to idle"); req->rcmd = RCMD_IDLE; req->open = TRUE; } - else if(!strncmp(CMD_STREAM, cmd, strlen(CMD_STREAM))) { + else if(!strncmp(CMD_STREAM, cmd, CURL_CSTRLEN(CMD_STREAM))) { logmsg("instructed to stream"); req->rcmd = RCMD_STREAM; } else if(!strncmp(CMD_CONNECTIONMONITOR, cmd, - strlen(CMD_CONNECTIONMONITOR))) { + CURL_CSTRLEN(CMD_CONNECTIONMONITOR))) { logmsg("enabled connection monitoring"); req->connmon = TRUE; } - else if(!strncmp(CMD_UPGRADE, cmd, strlen(CMD_UPGRADE))) { + else if(!strncmp(CMD_UPGRADE, cmd, CURL_CSTRLEN(CMD_UPGRADE))) { logmsg("enabled upgrade"); req->upgrade = TRUE; } - else if(!strncmp(CMD_SWSCLOSE, cmd, strlen(CMD_SWSCLOSE))) { + else if(!strncmp(CMD_SWSCLOSE, cmd, CURL_CSTRLEN(CMD_SWSCLOSE))) { logmsg("swsclose: close this connection after response"); req->close = TRUE; } @@ -292,7 +292,7 @@ static int sws_parse_servercmd(struct sws_httprequest *req) logmsg("instructed to skip this number of bytes %d", num); req->skip = num; } - else if(!strncmp(CMD_NOEXPECT, cmd, strlen(CMD_NOEXPECT))) { + else if(!strncmp(CMD_NOEXPECT, cmd, CURL_CSTRLEN(CMD_NOEXPECT))) { logmsg("instructed to reject Expect: 100-continue"); req->noexpect = TRUE; } @@ -591,7 +591,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req) ignore the content-length, we return as soon as all headers have been received */ curl_off_t clen; - const char *p = line + strlen("Content-Length:"); + const char *p = line + CURL_CSTRLEN("Content-Length:"); if(curlx_str_numblanks(&p, &clen)) { /* this assumes that a zero Content-Length is valid */ logmsg("Found invalid '%s' in the request", line); @@ -608,12 +608,13 @@ static int sws_ProcessRequest(struct sws_httprequest *req) logmsg("... but going to abort after %zu bytes", req->cl); } else if(!CURL_STRNICMP("Transfer-Encoding: chunked", line, - strlen("Transfer-Encoding: chunked"))) { + CURL_CSTRLEN("Transfer-Encoding: chunked"))) { /* chunked data coming in */ chunked = TRUE; } - else if(req->noexpect && !CURL_STRNICMP("Expect: 100-continue", line, - strlen("Expect: 100-continue"))) { + else if(req->noexpect && + !CURL_STRNICMP("Expect: 100-continue", line, + CURL_CSTRLEN("Expect: 100-continue"))) { if(req->cl) req->cl = 0; req->skipall = TRUE; @@ -709,8 +710,8 @@ static int sws_ProcessRequest(struct sws_httprequest *req) req->prot_version >= 11 && req->reqbuf + req->offset > end + strlen(end_of_headers) && !req->cl && - (!strncmp(req->reqbuf, "GET", strlen("GET")) || - !strncmp(req->reqbuf, "HEAD", strlen("HEAD")))) { + (!strncmp(req->reqbuf, "GET", CURL_CSTRLEN("GET")) || + !strncmp(req->reqbuf, "HEAD", CURL_CSTRLEN("HEAD")))) { /* If we have a persistent connection, HTTP version >= 1.1 and GET/HEAD request, enable pipelining. */ req->checkindex = (end - req->reqbuf) + strlen(end_of_headers); @@ -771,10 +772,10 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req) case RCMD_STREAM: { static const char streamthis[] = "a string to stream 01234567890\n"; for(;;) { - written = swrite(sock, streamthis, sizeof(streamthis) - 1); + written = swrite(sock, streamthis, CURL_CSTRLEN(streamthis)); if(got_exit_signal) return -1; - if(written != (ssize_t)(sizeof(streamthis) - 1)) { + if(written != (ssize_t)CURL_CSTRLEN(streamthis)) { logmsg("Stopped streaming"); break; } @@ -2325,8 +2326,9 @@ static int test_sws(int argc, const char *argv[]) logmsg("====> Client disconnect %d", req->connmon); if(req->connmon) { - const char *keepopen = "[DISCONNECT]\n"; - storerequest(keepopen, strlen(keepopen), REQUEST_DUMP_FILENAME); + static const char keepopen[] = "[DISCONNECT]\n"; + storerequest(keepopen, CURL_CSTRLEN(keepopen), + REQUEST_DUMP_FILENAME); } if(!req->open) diff --git a/tests/tunit/tool1720.c b/tests/tunit/tool1720.c index 80e3c157ba..486d57e630 100644 --- a/tests/tunit/tool1720.c +++ b/tests/tunit/tool1720.c @@ -28,7 +28,7 @@ static CURLcode test_tool1720(const char *arg) { UNITTEST_BEGIN_SIMPLE - static const char *check[] = { + static const char * const check[] = { "", "(null)", "filename", diff --git a/tests/unit/unit1303.c b/tests/unit/unit1303.c index 50cdaa12f1..52a7ea9c43 100644 --- a/tests/unit/unit1303.c +++ b/tests/unit/unit1303.c @@ -85,7 +85,7 @@ static CURLcode test_unit1303(const char *arg) const char *comment; }; - const struct timetest run[] = { + static const struct timetest run[] = { /* both timeouts set, not connecting */ {BASE + 4, 0, 10000, 8000, FALSE, 6000, "6 seconds should be left"}, {BASE + 4, 990000, 10000, 8000, FALSE, 5010, "5010 ms should be left"}, diff --git a/tests/unit/unit1395.c b/tests/unit/unit1395.c index d25d0e3005..a286303977 100644 --- a/tests/unit/unit1395.c +++ b/tests/unit/unit1395.c @@ -35,7 +35,7 @@ static CURLcode test_unit1395(const char *arg) const char *output; }; - const struct dotdot pairs[] = { + static const struct dotdot pairs[] = { { "/%2f%2e%2e%2f/../a", "/a" }, { "/%2f%2e%2e%2f/../", "/" }, { "/%2f%2e%2e%2f/.", "/%2f%2e%2e%2f/" }, diff --git a/tests/unit/unit1396.c b/tests/unit/unit1396.c index 5b03e092bb..1dd3c17112 100644 --- a/tests/unit/unit1396.c +++ b/tests/unit/unit1396.c @@ -51,7 +51,7 @@ static CURLcode test_unit1396(const char *arg) }; /* unescape, this => that */ - const struct test list1[] = { + static const struct test list1[] = { { "%61", 3, "a", 1 }, { "%61a", 4, "aa", 2 }, { "%61b", 4, "ab", 2 }, @@ -67,7 +67,7 @@ static CURLcode test_unit1396(const char *arg) { NULL, 0, NULL, 0 } /* end of list marker */ }; /* escape, this => that */ - const struct test list2[] = { + static const struct test list2[] = { { "a", 1, "a", 1 }, { "/", 1, "%2F", 3 }, { "a=b", 3, "a%3Db", 5 }, diff --git a/tests/unit/unit1398.c b/tests/unit/unit1398.c index 7f2267e438..2147a4a283 100644 --- a/tests/unit/unit1398.c +++ b/tests/unit/unit1398.c @@ -34,7 +34,7 @@ static CURLcode test_unit1398(const char *arg) int rc; char buf[3] = { 'b', 'u', 'g' }; - static const char *str = "bug"; + static const char str[] = "bug"; int width = 3; char output[130]; diff --git a/tests/unit/unit1625.c b/tests/unit/unit1625.c index 9ca59b9402..21e37370c1 100644 --- a/tests/unit/unit1625.c +++ b/tests/unit/unit1625.c @@ -41,8 +41,8 @@ static CURLcode test_unit1625(const char *arg) char *large; size_t i; const size_t large_value_len = MAX_HTTP_RESP_HEADER_SIZE; - const size_t large_prefix_len = strlen("Encoding: "); - const size_t large_suffix_len = strlen(", chunked"); + const size_t large_prefix_len = CURL_CSTRLEN("Encoding: "); + const size_t large_suffix_len = CURL_CSTRLEN(", chunked"); static const struct check1625 list[] = { /* basic case */ { "Encoding: gzip, chunked", "Encoding:", "chunked", TRUE }, diff --git a/tests/unit/unit1627.c b/tests/unit/unit1627.c index 1d1f598358..06bd30cff5 100644 --- a/tests/unit/unit1627.c +++ b/tests/unit/unit1627.c @@ -32,7 +32,7 @@ static CURLcode test_unit1627(const char *arg) size_t i, j; /* existing schemes in different cases */ - static const char *okay[] = { + static const char * const okay[] = { /* all upper */ "DICT", "FILE", "FTP", "FTPS", "GOPHER", "GOPHERS", "HTTP", "HTTPS", "IMAP", "IMAPS", "LDAP", "LDAPS", "MQTT", "MQTTS", "POP3", "POP3S", @@ -50,7 +50,7 @@ static CURLcode test_unit1627(const char *arg) "TELNEt", "tFTP", "Ws", "wSS", }; /* non-existing schemes */ - static const char *notokay[] = { + static const char * const notokay[] = { "a", "A", "htt", "ttp", "httt", "http+", "HTTPP", "HTTPPS", "HTTSP", "GROPHER", "D1CT", "AbG", "zLQp", "mNrtW", "PkY", "bVcxZq", "LmO", "iUhyT", "rEwQA", "xSdfG", "nBvC", "pOiuY", "tRewQ", "aSdfG", "hJkl", diff --git a/tests/unit/unit1650.c b/tests/unit/unit1650.c index 4e307474fd..299a19bfd4 100644 --- a/tests/unit/unit1650.c +++ b/tests/unit/unit1650.c @@ -54,8 +54,10 @@ static CURLcode test_unit1650(const char *arg) }; static const struct dohrequest req[] = { - {"test.host.name", CURL_DNS_TYPE_A, DNS_Q1, sizeof(DNS_Q1)-1, DOH_OK }, - {"test.host.name", CURL_DNS_TYPE_AAAA, DNS_Q2, sizeof(DNS_Q2)-1, DOH_OK }, + {"test.host.name", + CURL_DNS_TYPE_A, DNS_Q1, CURL_CSTRLEN(DNS_Q1), DOH_OK }, + {"test.host.name", + CURL_DNS_TYPE_AAAA, DNS_Q2, CURL_CSTRLEN(DNS_Q2), DOH_OK }, {"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" ".host.name", CURL_DNS_TYPE_AAAA, NULL, 0, DOH_DNS_BAD_LABEL } @@ -235,7 +237,7 @@ static CURLcode test_unit1650(const char *arg) } /* pass all sizes into the decoder until full */ - for(i = 0; i < sizeof(full49) - 1; i++) { + for(i = 0; i < CURL_CSTRLEN(full49); i++) { struct dohentry d; DOHcode rc; memset(&d, 0, sizeof(d)); @@ -267,8 +269,8 @@ static CURLcode test_unit1650(const char *arg) struct dohentry d; struct dohaddr *a; memset(&d, 0, sizeof(d)); - rc = doh_resp_decode((const unsigned char *)full49, - sizeof(full49) - 1, CURL_DNS_TYPE_A, &d); + rc = doh_resp_decode((const unsigned char *)full49, CURL_CSTRLEN(full49), + CURL_DNS_TYPE_A, &d); fail_if(d.numaddr != 1, "missing address"); a = &d.addr[0]; p = &a->ip.v4[0]; diff --git a/tests/unit/unit1655.c b/tests/unit/unit1655.c index ff3dc53481..55e9020989 100644 --- a/tests/unit/unit1655.c +++ b/tests/unit/unit1655.c @@ -132,9 +132,9 @@ static CURLcode test_unit1655(const char *arg) const size_t buflen = sizeof(buffer); const size_t magic1 = 9765; size_t olen1 = magic1; - static const char *sunshine1 = "a.com"; - static const char *dotshine1 = "a.com."; - static const char *sunshine2 = "aa.com"; + static const char sunshine1[] = "a.com"; + static const char dotshine1[] = "a.com."; + static const char sunshine2[] = "aa.com"; size_t olen2; DOHcode ret2; size_t olen; diff --git a/tests/unit/unit1664.c b/tests/unit/unit1664.c index 17a04a37f2..f4574d485c 100644 --- a/tests/unit/unit1664.c +++ b/tests/unit/unit1664.c @@ -41,7 +41,7 @@ static CURLcode test_unit1664(const char *arg) { UNITTEST_BEGIN(t1664_setup()) - static const char *wordparse[] = { + static const char * const wordparse[] = { "word", "word ", " word ", @@ -78,7 +78,7 @@ static CURLcode test_unit1664(const char *arg) } { - static const char *qwords[] = { + static const char * const qwords[] = { "\"word\"", "\"word", "word\"", @@ -112,7 +112,7 @@ static CURLcode test_unit1664(const char *arg) } { - static const char *single[] = { + static const char * const single[] = { "a", "aa", "A", @@ -133,7 +133,7 @@ static CURLcode test_unit1664(const char *arg) } { - static const char *single[] = { + static const char * const single[] = { "a", "aa", "A", @@ -156,7 +156,7 @@ static CURLcode test_unit1664(const char *arg) } { - static const char *single[] = { + static const char * const single[] = { "a", "aa", "A", @@ -177,7 +177,7 @@ static CURLcode test_unit1664(const char *arg) } { - static const char *nums[] = { + static const char * const nums[] = { "1", "10000", "1234", @@ -313,7 +313,7 @@ static CURLcode test_unit1664(const char *arg) { /* CURL_OFF_T is typically 9223372036854775807 */ - static const char *nums[] = { + static const char * const nums[] = { "9223372036854775807", /* 2^63 -1 */ "9223372036854775808", /* 2^63 */ "18446744073709551615", /* 2^64 - 1 */ @@ -347,7 +347,7 @@ static CURLcode test_unit1664(const char *arg) } { - static const char *newl[] = { + static const char * const newl[] = { "a", "aa", "A", @@ -372,7 +372,7 @@ static CURLcode test_unit1664(const char *arg) } { - static const char *nums[] = { + static const char * const nums[] = { "1", "1000", "1234", @@ -399,7 +399,7 @@ static CURLcode test_unit1664(const char *arg) } { - static const char *nums[] = { + static const char * const nums[] = { "1", "1000", "1234", @@ -427,7 +427,7 @@ static CURLcode test_unit1664(const char *arg) { /* CURL_OFF_T is typically 2^63-1 */ - static const char *nums[] = { + static const char * const nums[] = { "777777777777777777777", /* 2^63 -1 */ "1000000000000000000000", /* 2^63 */ "111111111111111111111", @@ -451,7 +451,7 @@ static CURLcode test_unit1664(const char *arg) { /* CURL_OFF_T is typically 2^63-1 */ - static const char *nums[] = { + static const char * const nums[] = { "7FFFFFFFFFFFFFFF", /* 2^63 -1 */ "8000000000000000", /* 2^63 */ "1111111111111111", diff --git a/tests/unit/unit1666.c b/tests/unit/unit1666.c index c2f20c977a..cf272da42f 100644 --- a/tests/unit/unit1666.c +++ b/tests/unit/unit1666.c @@ -36,7 +36,7 @@ struct test_1666 { }; /* the size of the object needs to deduct the null-terminator */ -#define OID(x) x, sizeof(x) - 1 +#define OID(x) STRCONST(x) static bool test1666(const struct test_1666 *spec, size_t i, struct dynbuf *dbuf) diff --git a/tests/unit/unit1675.c b/tests/unit/unit1675.c index 7e869651d0..1d7c44d461 100644 --- a/tests/unit/unit1675.c +++ b/tests/unit/unit1675.c @@ -38,7 +38,7 @@ static CURLcode test_unit1675(const char *arg) const char *in; const char *out; }; - const struct ipv4_test tests[] = { + static const struct ipv4_test tests[] = { { "0x.0x.0x.0x", NULL }, /* invalid hex */ { "0x.0x.0x", NULL }, /* invalid hex */ { "0x.0x", NULL }, /* invalid hex */ @@ -146,7 +146,7 @@ static CURLcode test_unit1675(const char *arg) unsigned int query; const char *out; }; - const struct urlencode_test tests[] = { + static const struct urlencode_test tests[] = { { "http://leave\x01/hello\x01world", FALSE, QUERY_NO, "http://leave\x01/hello%01world" }, { "http://leave/hello\x01world", FALSE, QUERY_NO, @@ -204,7 +204,7 @@ static CURLcode test_unit1675(const char *arg) const char *out_host; const char *out_zone; }; - const struct ipv6_test tests[] = { + static const struct ipv6_test tests[] = { { "[::1]", "[::1]", NULL }, { "[fe80::1%eth0]", "[fe80::1]", "eth0" }, { "[fe80::1%25eth0]", "[fe80::1]", "eth0" }, @@ -260,7 +260,7 @@ static CURLcode test_unit1675(const char *arg) const char *out_path; bool fine; }; - const struct file_test tests[] = { + static const struct file_test tests[] = { { "file:///etc/hosts", "/etc/hosts", TRUE }, { "file://localhost/etc/hosts", "/etc/hosts", TRUE }, { "file://apple/etc/hosts", "/etc/hosts", FALSE }, @@ -317,7 +317,7 @@ static CURLcode test_unit1675(const char *arg) const char *path; bool expect_match; }; - const struct origin_test tests[] = { + static const struct origin_test tests[] = { { "http://host:123/x", "http", "host", "123", "/y", TRUE }, { "http://host:123/x", NULL, "host", "123", "/y", TRUE }, { "http://host:123/x", NULL, NULL, NULL, "/y", TRUE }, @@ -395,7 +395,7 @@ loop_end: const char *options; size_t offset; }; - const struct test tests[] = { + static const struct test tests[] = { { CURLUE_OK, "foo:bar@host", NULL, 0, "foo", "bar", "o", 8 }, { CURLUE_OK, "foo:bar;abc@host", "imap", 0, "foo", "bar", "abc", 12 }, { CURLUE_OK, "foo:bar;abc@host", NULL, 0, "foo", "bar;abc", "o", 12 }, diff --git a/tests/unit/unit2603.c b/tests/unit/unit2603.c index 0198ccf7f4..f2ec4f6b90 100644 --- a/tests/unit/unit2603.c +++ b/tests/unit/unit2603.c @@ -48,7 +48,7 @@ static void check_eq(const char *s, const char *exp_s, const char *name) } struct tcase { - const char **input; + const char * const *input; const char *default_scheme; const char *custom_method; const char *method; @@ -117,7 +117,7 @@ static CURLcode test_unit2603(const char *arg) UNITTEST_BEGIN_SIMPLE #ifndef CURL_DISABLE_HTTP - static const char *T1_INPUT[] = { + static const char * const T1_INPUT[] = { "GET /path HTTP/1.1\r\nHost: test.curl.se\r\n\r\n", NULL, }; @@ -128,7 +128,7 @@ static CURLcode test_unit2603(const char *arg) T1_INPUT, "https", NULL, "GET", "https", NULL, "/path", 1, 0 }; - static const char *T2_INPUT[] = { + static const char * const T2_INPUT[] = { "GET /path HTT", "P/1.1\r\nHost: te", "st.curl.se\r\n\r", @@ -139,7 +139,7 @@ static CURLcode test_unit2603(const char *arg) T2_INPUT, NULL, NULL, "GET", NULL, NULL, "/path", 1, 8 }; - static const char *T3_INPUT[] = { + static const char * const T3_INPUT[] = { "GET ftp://ftp.curl.se/xxx?a=2 HTTP/1.1\r\nContent-Length: 0\r", "\nUser-Agent: xxx\r\n\r\n", NULL, @@ -148,7 +148,7 @@ static CURLcode test_unit2603(const char *arg) T3_INPUT, NULL, NULL, "GET", "ftp", "ftp.curl.se", "/xxx?a=2", 2, 0 }; - static const char *T4_INPUT[] = { + static const char * const T4_INPUT[] = { "CONNECT ftp.curl.se:123 HTTP/1.1\r\nContent-Length: 0\r\n", "User-Agent: xxx\r\n", "nothing: \r\n\r\n\n\n", @@ -158,7 +158,7 @@ static CURLcode test_unit2603(const char *arg) T4_INPUT, NULL, NULL, "CONNECT", NULL, "ftp.curl.se:123", NULL, 3, 2 }; - static const char *T6_INPUT[] = { + static const char * const T6_INPUT[] = { "PUT /path HTTP/1.1\nHost: test.curl.se\n\n123", NULL, }; @@ -167,7 +167,7 @@ static CURLcode test_unit2603(const char *arg) }; /* test a custom method with space, #19543 */ - static const char *T7_INPUT[] = { + static const char * const T7_INPUT[] = { "IN SANE /path HTTP/1.1\r\nContent-Length: 0\r\n\r\n", NULL, }; diff --git a/tests/unit/unit3200.c b/tests/unit/unit3200.c index 3a7a37597c..23e5d56713 100644 --- a/tests/unit/unit3200.c +++ b/tests/unit/unit3200.c @@ -45,7 +45,7 @@ static CURLcode test_unit3200(const char *arg) #define C1024 C256 C256 C256 C256 #define C4096 C1024 C1024 C1024 C1024 - static const char *filecontents[] = { + static const char * const filecontents[] = { /* Both should be read */ "LINE1\n" "LINE2 NEWLINE\n", diff --git a/tests/unit/unit3205.c b/tests/unit/unit3205.c index 039b679d0a..234d8ae933 100644 --- a/tests/unit/unit3205.c +++ b/tests/unit/unit3205.c @@ -420,7 +420,7 @@ static CURLcode test_unit3205(const char *arg) #endif }; - static const char *cs_test_string = + static const char cs_test_string[] = "TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:" "TLS_CHACHA20_POLY1305_SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:" "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:" @@ -561,11 +561,12 @@ static CURLcode test_unit3205(const char *arg) if(test->id >= 0x0011 && test->id < 0x0017) { if(expect && !memcmp(expect, "EDH-", 4)) { curlx_strcopy(alt, sizeof(alt), expect, strlen(expect)); - expect = (const char *)memcpy(alt, "DHE-", sizeof("DHE-") - 1); + expect = memcpy(alt, "DHE-", CURL_CSTRLEN("DHE-")); } if(expect && !memcmp(expect + 4, "EDH-", 4)) { curlx_strcopy(alt, sizeof(alt), expect, strlen(expect)); - expect = (const char *)memcpy(alt + 4, "DHE-", sizeof("DHE-") - 1) - 4; + expect = memcpy(alt + 4, "DHE-", CURL_CSTRLEN("DHE-")); + expect -= 4; } } diff --git a/tests/unit/unit3400.c b/tests/unit/unit3400.c index 060cc61799..364a2b540f 100644 --- a/tests/unit/unit3400.c +++ b/tests/unit/unit3400.c @@ -56,13 +56,13 @@ static void check_capsule_hdr(size_t payload_len, static void test_capsule_encap_udp_hdr_boundaries(void) { - const unsigned char p0[] = { 0x00, 0x01, 0x00 }; - const unsigned char p62[] = { 0x00, 0x3F, 0x00 }; - const unsigned char p63[] = { 0x00, 0x40, 0x40, 0x00 }; - const unsigned char p64[] = { 0x00, 0x40, 0x41, 0x00 }; - const unsigned char p16382[] = { 0x00, 0x7F, 0xFF, 0x00 }; - const unsigned char p16383[] = { 0x00, 0x80, 0x00, 0x40, 0x00, 0x00 }; - const unsigned char p16384[] = { 0x00, 0x80, 0x00, 0x40, 0x01, 0x00 }; + static const unsigned char p0[] = { 0x00, 0x01, 0x00 }; + static const unsigned char p62[] = { 0x00, 0x3F, 0x00 }; + static const unsigned char p63[] = { 0x00, 0x40, 0x40, 0x00 }; + static const unsigned char p64[] = { 0x00, 0x40, 0x41, 0x00 }; + static const unsigned char p16382[] = { 0x00, 0x7F, 0xFF, 0x00 }; + static const unsigned char p16383[] = { 0x00, 0x80, 0x00, 0x40, 0x00, 0x00 }; + static const unsigned char p16384[] = { 0x00, 0x80, 0x00, 0x40, 0x01, 0x00 }; check_capsule_hdr(0, p0, sizeof(p0)); check_capsule_hdr(62, p62, sizeof(p62)); @@ -139,7 +139,7 @@ static void test_capsule_sequential_decode(void) CURLcode err; size_t nread; /* Two back-to-back 3-byte UDP capsules */ - const unsigned char two_caps[] = { + static const unsigned char two_caps[] = { 0x00, 0x04, 0x00, 0x11, 0x22, 0x33, /* capsule 1: [0x11,0x22,0x33] */ 0x00, 0x04, 0x00, 0xAA, 0xBB, 0xCC /* capsule 2: [0xAA,0xBB,0xCC] */ }; @@ -186,13 +186,15 @@ static void test_capsule_decode_paths(void) unsigned char out[8]; CURLcode err = CURLE_OK; size_t nread; - const unsigned char invalid_type[] = { 0x01 }; - const unsigned char partial_len[] = { 0x00, 0x40 }; - const unsigned char invalid_context[] = { 0x00, 0x01, 0x01 }; - const unsigned char invalid_caps_len[] = { 0x00, 0x00, 0x00 }; - const unsigned char partial_payload[] = { 0x00, 0x04, 0x00, 0x11, 0x22 }; - const unsigned char payload_3b[] = { 0x00, 0x04, 0x00, 0x11, 0x22, 0x33 }; - const unsigned char payload_empty[] = { 0x00, 0x01, 0x00 }; + static const unsigned char invalid_type[] = { 0x01 }; + static const unsigned char partial_len[] = { 0x00, 0x40 }; + static const unsigned char invalid_context[] = { 0x00, 0x01, 0x01 }; + static const unsigned char invalid_caps_len[] = { 0x00, 0x00, 0x00 }; + static const unsigned char partial_payload[] = { 0x00, 0x04, 0x00, 0x11, + 0x22 }; + static const unsigned char payload_3b[] = { 0x00, 0x04, 0x00, + 0x11, 0x22, 0x33 }; + static const unsigned char payload_empty[] = { 0x00, 0x01, 0x00 }; Curl_bufq_init2(&q, 32, 4, BUFQ_OPT_NONE);