From: Viktor Szakats Date: Sun, 1 Feb 2026 02:57:45 +0000 (+0100) Subject: build: use more `const` X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=963059365088a6e9929c44da9ae2244fdcb44065;p=thirdparty%2Fcurl.git build: use more `const` Mostly with `char *` types. Also: - mime, x509asn1, tool_operate, lib3207: drop redundant casts. - examples/smooth-gtk-thread: add missing variable declaration. - reduce variable scopes. - tests/server: move `data_to_hex()` to its only user: `sws`. Closes #20489 --- diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index e5cd1f1ad9..6bc2bd71df 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -131,7 +131,7 @@ int main(void) /* !checksrc! disable EQUALSNULL 1 */ while((msg = curl_multi_info_read(multi, &msgs_left)) != NULL) { if(msg->msg == CURLMSG_DONE) { - char *url; + const char *url; CURL *curl = msg->easy_handle; curl_easy_getinfo(curl, CURLINFO_PRIVATE, &url); fprintf(stderr, "R: %d - %s <%s>\n", diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index cdc0ad9e5f..a44194aaa5 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -88,15 +88,15 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *stream) return nread; } -int main(int argc, char **argv) +int main(int argc, const char **argv) { CURL *curl; CURLcode result; FILE *fp; struct stat file_info; - char *file; - char *url; + const char *file; + const char *url; if(argc < 3) return 1; diff --git a/docs/examples/block_ip.c b/docs/examples/block_ip.c index f4a2827567..6bf0625fdd 100644 --- a/docs/examples/block_ip.c +++ b/docs/examples/block_ip.c @@ -191,8 +191,8 @@ static int ip_match(struct ip *ip, void *netaddr) int bytes, tailbits; const unsigned char *x, *y; - x = (unsigned char *)&ip->netaddr; - y = (unsigned char *)netaddr; + x = (const unsigned char *)&ip->netaddr; + y = (const unsigned char *)netaddr; for(bytes = ip->maskbits / 8; bytes; --bytes) { if(*x++ != *y++) @@ -214,7 +214,7 @@ static int is_ipv4_mapped_ipv6_address(int family, void *netaddr) { if(family == AF_INET6) { int i; - unsigned char *x = (unsigned char *)netaddr; + const unsigned char *x = (const unsigned char *)netaddr; for(i = 0; i < 12; ++i) { if(x[i]) break; diff --git a/docs/examples/chkspeed.c b/docs/examples/chkspeed.c index 3e8181e16f..f6f7080864 100644 --- a/docs/examples/chkspeed.c +++ b/docs/examples/chkspeed.c @@ -66,13 +66,13 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) return (size_t)(size * nmemb); } -int main(int argc, char *argv[]) +int main(int argc, const char *argv[]) { CURL *curl; CURLcode result; int prtall = 0, prtsep = 0, prttime = 0; const char *url = URL_1M; - char *appname = argv[0]; + const char *appname = argv[0]; if(argc > 1) { /* parse input parameters */ diff --git a/docs/examples/ftp-wildcard.c b/docs/examples/ftp-wildcard.c index 4cade8d174..e8f0be6263 100644 --- a/docs/examples/ftp-wildcard.c +++ b/docs/examples/ftp-wildcard.c @@ -97,7 +97,7 @@ static size_t write_cb(char *buff, size_t size, size_t nmemb, void *cb_data) return written; } -int main(int argc, char **argv) +int main(int argc, const char **argv) { /* curl easy handle */ CURL *curl; diff --git a/docs/examples/getinfo.c b/docs/examples/getinfo.c index 66bb69b8ae..1635fcc224 100644 --- a/docs/examples/getinfo.c +++ b/docs/examples/getinfo.c @@ -43,7 +43,7 @@ int main(void) result = curl_easy_perform(curl); if(CURLE_OK == result) { - char *ct; + const char *ct; /* ask for the content-type */ result = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct); diff --git a/docs/examples/getredirect.c b/docs/examples/getredirect.c index fabfc594bc..27c20ddb73 100644 --- a/docs/examples/getredirect.c +++ b/docs/examples/getredirect.c @@ -33,8 +33,6 @@ int main(void) { CURL *curl; CURLcode result; - char *location; - long response_code; result = curl_global_init(CURL_GLOBAL_ALL); if(result) @@ -53,12 +51,14 @@ int main(void) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(result)); else { + long response_code; result = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); if((result == CURLE_OK) && ((response_code / 100) != 3)) { /* a redirect implies a 3xx response code */ fprintf(stderr, "Not a redirect.\n"); } else { + const char *location; result = curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &location); if((result == CURLE_OK) && location) { diff --git a/docs/examples/getreferrer.c b/docs/examples/getreferrer.c index ac190f3fa1..cbe031763f 100644 --- a/docs/examples/getreferrer.c +++ b/docs/examples/getreferrer.c @@ -49,7 +49,7 @@ int main(void) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(result)); else { - char *hdr; + const char *hdr; result = curl_easy_getinfo(curl, CURLINFO_REFERER, &hdr); if((result == CURLE_OK) && hdr) printf("Referrer header: %s\n", hdr); diff --git a/docs/examples/htmltidy.c b/docs/examples/htmltidy.c index 3cd4f2a5ba..7c11afbb2a 100644 --- a/docs/examples/htmltidy.c +++ b/docs/examples/htmltidy.c @@ -74,7 +74,7 @@ static void dumpNode(TidyDoc doc, TidyNode tnod, int indent) } } -int main(int argc, char **argv) +int main(int argc, const char **argv) { CURL *curl; char curl_errbuf[CURL_ERROR_SIZE]; diff --git a/docs/examples/htmltitle.cpp b/docs/examples/htmltitle.cpp index 285908da16..ea62f93290 100644 --- a/docs/examples/htmltitle.cpp +++ b/docs/examples/htmltitle.cpp @@ -250,7 +250,7 @@ static void parseHtml(const std::string &html, title = context.title; } -int main(int argc, char *argv[]) +int main(int argc, const char *argv[]) { CURL *curl = NULL; CURLcode result; diff --git a/docs/examples/http2-download.c b/docs/examples/http2-download.c index 8f97b84f96..3e5dde1d2c 100644 --- a/docs/examples/http2-download.c +++ b/docs/examples/http2-download.c @@ -187,7 +187,7 @@ static int setup(struct transfer *t, int num) /* * Download many transfers over HTTP/2, using the same connection! */ -int main(int argc, char **argv) +int main(int argc, const char **argv) { CURLcode result; struct transfer *trans; diff --git a/docs/examples/http2-pushinmemory.c b/docs/examples/http2-pushinmemory.c index 37816742c0..a51232e359 100644 --- a/docs/examples/http2-pushinmemory.c +++ b/docs/examples/http2-pushinmemory.c @@ -93,7 +93,7 @@ static int server_push_callback(CURL *parent, struct curl_pushheaders *headers, void *userp) { - char *headp; + const char *headp; int *transfers = (int *)userp; (void)parent; (void)num_headers; diff --git a/docs/examples/http2-serverpush.c b/docs/examples/http2-serverpush.c index e570f2ed31..afeec76949 100644 --- a/docs/examples/http2-serverpush.c +++ b/docs/examples/http2-serverpush.c @@ -172,7 +172,7 @@ static int server_push_callback(CURL *parent, struct curl_pushheaders *headers, void *userp) { - char *headp; + const char *headp; size_t i; int *transfers = (int *)userp; char filename[128]; @@ -214,7 +214,7 @@ static int server_push_callback(CURL *parent, /* * Download a file over HTTP/2, take care of server push. */ -int main(int argc, char *argv[]) +int main(int argc, const char *argv[]) { CURLcode result; CURL *curl; diff --git a/docs/examples/http2-upload.c b/docs/examples/http2-upload.c index d0081cc49b..b2657940e5 100644 --- a/docs/examples/http2-upload.c +++ b/docs/examples/http2-upload.c @@ -285,7 +285,7 @@ static int setup(struct input *t, int num, const char *upload) /* * Upload all files over HTTP/2, using the same physical connection! */ -int main(int argc, char **argv) +int main(int argc, const char **argv) { CURLcode result; struct input *trans; diff --git a/docs/examples/httpput-postfields.c b/docs/examples/httpput-postfields.c index 7163756a36..88eb55f06e 100644 --- a/docs/examples/httpput-postfields.c +++ b/docs/examples/httpput-postfields.c @@ -47,11 +47,11 @@ static const char olivertwist[] = * CURLOPT_POSTFIELDS to the URL given as an argument. */ -int main(int argc, char **argv) +int main(int argc, const char **argv) { CURL *curl; CURLcode result; - char *url; + const char *url; if(argc < 2) return 1; diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 9a8163ce88..9fd808814f 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -73,15 +73,15 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *stream) return retcode; } -int main(int argc, char **argv) +int main(int argc, const char **argv) { CURL *curl; CURLcode result; FILE *hd_src; struct stat file_info; - char *file; - char *url; + const char *file; + const char *url; if(argc < 3) return 1; diff --git a/docs/examples/multi-event.c b/docs/examples/multi-event.c index 4d30ac8c62..b748238904 100644 --- a/docs/examples/multi-event.c +++ b/docs/examples/multi-event.c @@ -213,7 +213,7 @@ static int handle_socket(CURL *curl, curl_socket_t s, int action, void *userp, return 0; } -int main(int argc, char **argv) +int main(int argc, const char **argv) { CURLcode result; diff --git a/docs/examples/multi-uv.c b/docs/examples/multi-uv.c index a59c5988d9..6928408461 100644 --- a/docs/examples/multi-uv.c +++ b/docs/examples/multi-uv.c @@ -227,7 +227,7 @@ static int cb_socket(CURL *curl, curl_socket_t s, int action, return 0; } -int main(int argc, char **argv) +int main(int argc, const char **argv) { CURLcode result; struct datauv uv = { 0 }; diff --git a/docs/examples/postit2-formadd.c b/docs/examples/postit2-formadd.c index aee12ab0ac..3c297478ff 100644 --- a/docs/examples/postit2-formadd.c +++ b/docs/examples/postit2-formadd.c @@ -45,7 +45,7 @@ #include -int main(int argc, char *argv[]) +int main(int argc, const char *argv[]) { CURL *curl; CURLcode result; diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c index 4535bed6e1..5632717cd4 100644 --- a/docs/examples/postit2.c +++ b/docs/examples/postit2.c @@ -42,7 +42,7 @@ #include -int main(int argc, char *argv[]) +int main(int argc, const char *argv[]) { CURL *curl; diff --git a/docs/examples/smooth-gtk-thread.c b/docs/examples/smooth-gtk-thread.c index c82e0c57bf..64595f3955 100644 --- a/docs/examples/smooth-gtk-thread.c +++ b/docs/examples/smooth-gtk-thread.c @@ -65,7 +65,7 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, FILE *stream) return fwrite(ptr, size, nmemb, stream); } -static void run_one(gchar *http, int j) +static void run_one(const gchar *http, int j) { CURL *curl; @@ -94,6 +94,7 @@ static void *pull_one_url(void *NaN) /* protect the reading and increasing of 'j' with a mutex */ pthread_mutex_lock(&lock); while(j < num_urls) { + gchar *http; int i = j; j++; pthread_mutex_unlock(&lock); @@ -165,7 +166,7 @@ static gboolean cb_delete(GtkWidget *window, gpointer data) return FALSE; } -int main(int argc, char **argv) +int main(int argc, const char **argv) { GtkWidget *top_window, *outside_frame, *inside_frame, *progress_bar; diff --git a/docs/examples/sslbackend.c b/docs/examples/sslbackend.c index 5615bec72d..e10eaaa217 100644 --- a/docs/examples/sslbackend.c +++ b/docs/examples/sslbackend.c @@ -40,7 +40,7 @@ * **** This example only works with libcurl 7.56.0 and later! **** */ -int main(int argc, char **argv) +int main(int argc, const char **argv) { const char *name = argc > 1 ? argv[1] : "openssl"; CURLsslset result; diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index 6209ebc314..e9b730d50a 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -126,7 +126,7 @@ static size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb, if(ShowAllHeader == 1) fprintf(stderr, "%.*s", (int)nmemb, (char *)ptr); - if((nmemb >= 5) && !strncmp((char *)ptr, "Date:", 5)) { + if((nmemb >= 5) && !strncmp((const char *)ptr, "Date:", 5)) { if(ShowAllHeader == 0) fprintf(stderr, "HTTP Server. %.*s", (int)nmemb, (char *)ptr); @@ -163,7 +163,7 @@ static size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb, } } - if((nmemb >= 12) && !strncmp((char *)ptr, "X-Cache: HIT", 12)) { + if((nmemb >= 12) && !strncmp((const char *)ptr, "X-Cache: HIT", 12)) { fprintf(stderr, "ERROR: HTTP Server data is cached." " Server Date is no longer valid.\n"); AutoSyncTime = 0; @@ -226,7 +226,7 @@ static void showUsage(void) return; } -int main(int argc, char *argv[]) +int main(int argc, const char *argv[]) { CURLcode result; CURL *curl; diff --git a/docs/examples/url2file.c b/docs/examples/url2file.c index 0c9c5880f7..3370ac2f79 100644 --- a/docs/examples/url2file.c +++ b/docs/examples/url2file.c @@ -42,7 +42,7 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *stream) return written; } -int main(int argc, char *argv[]) +int main(int argc, const char *argv[]) { static const char *pagefilename = "page.out"; diff --git a/lib/cf-h1-proxy.c b/lib/cf-h1-proxy.c index ccc8349b1b..a85cd1d5a6 100644 --- a/lib/cf-h1-proxy.c +++ b/lib/cf-h1-proxy.c @@ -241,7 +241,7 @@ static CURLcode send_CONNECT(struct Curl_cfilter *cf, struct h1_tunnel_state *ts, bool *done) { - uint8_t *buf = curlx_dyn_uptr(&ts->request_data); + const uint8_t *buf = curlx_dyn_uptr(&ts->request_data); size_t request_len = curlx_dyn_len(&ts->request_data); size_t blen = request_len; CURLcode result = CURLE_OK; @@ -262,7 +262,7 @@ static CURLcode send_CONNECT(struct Curl_cfilter *cf, DEBUGASSERT(blen >= nwritten); ts->nsent += nwritten; - Curl_debug(data, CURLINFO_HEADER_OUT, (char *)buf, nwritten); + Curl_debug(data, CURLINFO_HEADER_OUT, (const char *)buf, nwritten); out: if(result) @@ -353,9 +353,9 @@ static CURLcode single_header(struct Curl_cfilter *cf, struct h1_tunnel_state *ts) { CURLcode result = CURLE_OK; - char *linep = curlx_dyn_ptr(&ts->rcvbuf); + const char *linep = curlx_dyn_ptr(&ts->rcvbuf); size_t line_len = curlx_dyn_len(&ts->rcvbuf); /* bytes in this line */ - struct SingleRequest *k = &data->req; + const struct SingleRequest *k = &data->req; int writetype; ts->headerlines++; @@ -531,7 +531,7 @@ static CURLcode recv_CONNECT_resp(struct Curl_cfilter *cf, if(byte != 0x0a) continue; else { - char *linep = curlx_dyn_ptr(&ts->rcvbuf); + const char *linep = curlx_dyn_ptr(&ts->rcvbuf); size_t hlen = curlx_dyn_len(&ts->rcvbuf); if(hlen && ISNEWLINE(linep[0])) { /* end of headers */ diff --git a/lib/curl_get_line.c b/lib/curl_get_line.c index f4328405c7..0eae0029f9 100644 --- a/lib/curl_get_line.c +++ b/lib/curl_get_line.c @@ -41,7 +41,7 @@ CURLcode Curl_get_line(struct dynbuf *buf, FILE *input, bool *eof) curlx_dyn_reset(buf); while(1) { size_t rlen; - char *b = fgets(buffer, sizeof(buffer), input); + const char *b = fgets(buffer, sizeof(buffer), input); *eof = feof(input); diff --git a/lib/curl_ntlm_core.c b/lib/curl_ntlm_core.c index 2e978d7ef3..2edc7b07ce 100644 --- a/lib/curl_ntlm_core.c +++ b/lib/curl_ntlm_core.c @@ -551,9 +551,9 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_hash(const char *user, size_t userlen, * * Returns CURLE_OK on success. */ -CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, - unsigned char *challenge_client, - struct ntlmdata *ntlm, +CURLcode Curl_ntlm_core_mk_ntlmv2_resp(const unsigned char *ntlmv2hash, + const unsigned char *challenge_client, + const struct ntlmdata *ntlm, unsigned char **ntresp, unsigned int *ntresp_len) { @@ -644,9 +644,9 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, * * Returns CURLE_OK on success. */ -CURLcode Curl_ntlm_core_mk_lmv2_resp(unsigned char *ntlmv2hash, - unsigned char *challenge_client, - unsigned char *challenge_server, +CURLcode Curl_ntlm_core_mk_lmv2_resp(const unsigned char *ntlmv2hash, + const unsigned char *challenge_client, + const unsigned char *challenge_server, unsigned char *lmresp) { unsigned char data[16]; diff --git a/lib/curl_ntlm_core.h b/lib/curl_ntlm_core.h index 947b836966..f96bf0ada5 100644 --- a/lib/curl_ntlm_core.h +++ b/lib/curl_ntlm_core.h @@ -55,15 +55,15 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_hash(const char *user, size_t userlen, unsigned char *ntlmhash, unsigned char *ntlmv2hash); -CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash, - unsigned char *challenge_client, - struct ntlmdata *ntlm, +CURLcode Curl_ntlm_core_mk_ntlmv2_resp(const unsigned char *ntlmv2hash, + const unsigned char *challenge_client, + const struct ntlmdata *ntlm, unsigned char **ntresp, unsigned int *ntresp_len); -CURLcode Curl_ntlm_core_mk_lmv2_resp(unsigned char *ntlmv2hash, - unsigned char *challenge_client, - unsigned char *challenge_server, +CURLcode Curl_ntlm_core_mk_lmv2_resp(const unsigned char *ntlmv2hash, + const unsigned char *challenge_client, + const unsigned char *challenge_server, unsigned char *lmresp); #endif /* !USE_WINDOWS_SSPI */ diff --git a/lib/curl_sasl.c b/lib/curl_sasl.c index 21e1b8d1f4..b2eb1fe884 100644 --- a/lib/curl_sasl.c +++ b/lib/curl_sasl.c @@ -227,13 +227,14 @@ static CURLcode get_server_message(struct SASL *sasl, struct Curl_easy *data, result = sasl->params->getmessage(data, out); if(!result && (sasl->params->flags & SASL_FLAG_BASE64)) { - unsigned char *msg; - size_t msglen; const char *serverdata = Curl_bufref_ptr(out); if(!*serverdata || *serverdata == '=') Curl_bufref_set(out, NULL, 0, NULL); else { + unsigned char *msg; + size_t msglen; + result = curlx_base64_decode(serverdata, &msg, &msglen); if(!result) Curl_bufref_set(out, msg, msglen, curl_free); diff --git a/lib/curlx/strerr.c b/lib/curlx/strerr.c index 1aa23aa570..d9c1686e44 100644 --- a/lib/curlx/strerr.c +++ b/lib/curlx/strerr.c @@ -292,7 +292,7 @@ const char *curlx_strerror(int err, char *buf, size_t buflen) */ { char buffer[256]; - char *msg = strerror_r(err, buffer, sizeof(buffer)); + const char *msg = strerror_r(err, buffer, sizeof(buffer)); if(msg && buflen > 1) SNPRINTF(buf, buflen, "%s", msg); else if(buflen > sizeof("Unknown error ") + 20) diff --git a/lib/formdata.c b/lib/formdata.c index bb2c702fe0..b22c255989 100644 --- a/lib/formdata.c +++ b/lib/formdata.c @@ -304,7 +304,7 @@ static CURLFORMcode FormAdd(struct curl_httppost **httppost, struct FormInfo *first_form, *curr, *form = NULL; CURLFORMcode retval = CURL_FORMADD_OK; CURLformoption option; - struct curl_forms *forms = NULL; + const struct curl_forms *forms = NULL; char *avalue = NULL; struct curl_httppost *newchain = NULL; struct curl_httppost *lastnode = NULL; diff --git a/lib/ftp.c b/lib/ftp.c index c9a472ca15..24e4796c88 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -886,7 +886,7 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, char myhost[MAX_IPADR_LEN + 1] = ""; struct Curl_sockaddr_storage ss; - struct Curl_addrinfo *res, *ai; + const struct Curl_addrinfo *res, *ai; curl_socklen_t sslen; char hbuf[NI_MAXHOST]; struct sockaddr *sa = (struct sockaddr *)&ss; @@ -896,15 +896,15 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, #endif static const char mode[][5] = { "EPRT", "PORT" }; int error; - char *host = NULL; - char *string_ftpport = data->set.str[STRING_FTPPORT]; + const char *host = NULL; + const char *string_ftpport = data->set.str[STRING_FTPPORT]; struct Curl_dns_entry *dns_entry = NULL; unsigned short port_min = 0; unsigned short port_max = 0; unsigned short port; bool possibly_non_local = TRUE; char buffer[STRERROR_LEN]; - char *addr = NULL; + const char *addr = NULL; size_t addrlen = 0; char ipstr[50]; @@ -920,7 +920,7 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, #ifdef USE_IPV6 if(*string_ftpport == '[') { /* [ipv6]:port(-range) */ - char *ip_start = string_ftpport + 1; + const char *ip_start = string_ftpport + 1; ip_end = strchr(ip_start, ']'); if(ip_end) { addrlen = ip_end - ip_start; @@ -1214,7 +1214,7 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, if(PORT == fcmd) { /* large enough for [IP address],[num],[num] */ char target[sizeof(myhost) + 20]; - char *source = myhost; + const char *source = myhost; char *dest = target; /* translate x.x.x.x to x,x,x,x */ @@ -1766,7 +1766,7 @@ static CURLcode ftp_state_quote(struct Curl_easy *data, i++; } if(item) { - char *cmd = item->data; + const char *cmd = item->data; if(cmd[0] == '*') { cmd++; ftpc->count2 = 1; /* the sent command is allowed to fail */ @@ -1924,11 +1924,11 @@ static CURLcode ftp_state_pasv_resp(struct Curl_easy *data, CURLcode result; struct Curl_dns_entry *dns = NULL; unsigned short connectport; /* the local port connect() should use! */ - struct pingpong *pp = &ftpc->pp; + const struct pingpong *pp = &ftpc->pp; char *newhost = NULL; unsigned short newport = 0; - char *str = curlx_dyn_ptr(&pp->recvbuf) + 4; /* start on the first letter */ - + const char *str = curlx_dyn_ptr(&pp->recvbuf) + 4; /* start on the first + letter */ if((ftpc->count1 == 0) && (ftpcode == 229)) { /* positive EPSV response */ @@ -2419,7 +2419,7 @@ static CURLcode ftp_state_mdtm_resp(struct Curl_easy *data, last .sss part is optional and means fractions of a second */ int year, month, day, hour, minute, second; struct pingpong *pp = &ftpc->pp; - char *resp = curlx_dyn_ptr(&pp->recvbuf) + 4; + const char *resp = curlx_dyn_ptr(&pp->recvbuf) + 4; bool showtime = FALSE; if(ftp_213_date(resp, &year, &month, &day, &hour, &minute, &second)) { /* we have a time, reformat it */ @@ -2561,7 +2561,7 @@ static CURLcode ftp_state_size_resp(struct Curl_easy *data, { CURLcode result = CURLE_OK; curl_off_t filesize = -1; - char *buf = curlx_dyn_ptr(&ftpc->pp.recvbuf); + const char *buf = curlx_dyn_ptr(&ftpc->pp.recvbuf); size_t len = ftpc->pp.nfinal; /* get the size from the ascii string: */ @@ -2569,7 +2569,7 @@ static CURLcode ftp_state_size_resp(struct Curl_easy *data, /* To allow servers to prepend "rubbish" in the response string, we scan for all the digits at the end of the response and parse only those as a number. */ - char *start = &buf[4]; + const char *start = &buf[4]; const char *fdigit = memchr(start, '\r', len - 4); if(fdigit) { fdigit--; @@ -2740,7 +2740,7 @@ static CURLcode ftp_state_get_resp(struct Curl_easy *data, size_t i; for(i = 0; i < len - 7; i++) { curl_off_t what; - char *buf = curlx_dyn_ptr(&ftpc->pp.recvbuf); + const char *buf = curlx_dyn_ptr(&ftpc->pp.recvbuf); const char *c = &buf[i]; if(!curlx_str_number(&c, &what, CURL_OFF_T_MAX) && !curlx_str_single(&c, ' ') && @@ -2910,8 +2910,8 @@ static CURLcode ftp_pwd_resp(struct Curl_easy *data, CURLcode result; if(ftpcode == 257) { - char *ptr = curlx_dyn_ptr(&pp->recvbuf) + 4; /* start on the first - letter */ + const char *ptr = curlx_dyn_ptr(&pp->recvbuf) + 4; /* start on the first + letter */ bool entry_extracted = FALSE; struct dynbuf out; curlx_dyn_init(&out, 1000); @@ -3183,10 +3183,10 @@ static CURLcode ftp_pp_statemachine(struct Curl_easy *data, case FTP_SYST: if(ftpcode == 215) { - char *ptr = curlx_dyn_ptr(&pp->recvbuf) + 4; /* start on the first - letter */ + const char *ptr = curlx_dyn_ptr(&pp->recvbuf) + 4; /* start on the first + letter */ + const char *start; char *os; - char *start; /* Reply format is like 215 @@ -3453,7 +3453,7 @@ static CURLcode ftp_sendquote(struct Curl_easy *data, while(item) { if(item->data) { size_t nread; - char *cmd = item->data; + const char *cmd = item->data; bool acceptfail = FALSE; CURLcode result; int ftpcode = 0; diff --git a/lib/getinfo.c b/lib/getinfo.c index a59c2d3eb2..fd0d483f0a 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -127,7 +127,7 @@ static CURLcode getinfo_char(struct Curl_easy *data, CURLINFO info, *param_charp = data->info.contenttype; break; case CURLINFO_PRIVATE: - *param_charp = (char *)data->set.private_data; + *param_charp = (const char *)data->set.private_data; break; case CURLINFO_FTP_ENTRY_PATH: /* Return the entrypath string from the most recent connection. diff --git a/lib/gopher.c b/lib/gopher.c index 49aeb10725..71ff39275c 100644 --- a/lib/gopher.c +++ b/lib/gopher.c @@ -63,8 +63,8 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) struct connectdata *conn = data->conn; curl_socket_t sockfd = conn->sock[FIRSTSOCKET]; char *gopherpath; - char *path = data->state.up.path; - char *query = data->state.up.query; + const char *path = data->state.up.path; + const char *query = data->state.up.query; const char *buf = NULL; char *buf_alloc = NULL; size_t nwritten, buf_len; @@ -91,7 +91,7 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) curlx_free(gopherpath); } else { - char *newp; + const char *newp; /* Otherwise, drop / and the first character (i.e., item type) ... */ newp = gopherpath; diff --git a/lib/hostip.c b/lib/hostip.c index 9c33108d34..f82b1ee950 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -118,7 +118,7 @@ static void show_resolve_info(struct Curl_easy *data, struct Curl_dns_entry *dns) { - struct Curl_addrinfo *a; + const struct Curl_addrinfo *a; CURLcode result = CURLE_OK; #ifdef CURLRES_IPV6 struct dynbuf out[2]; diff --git a/lib/http.c b/lib/http.c index b5627e61a8..26a15ad75e 100644 --- a/lib/http.c +++ b/lib/http.c @@ -4343,7 +4343,7 @@ static CURLcode http_rw_hd(struct Curl_easy *data, void Curl_http_to_fold(struct dynbuf *bf) { size_t len = curlx_dyn_len(bf); - char *hd = curlx_dyn_ptr(bf); + const char *hd = curlx_dyn_ptr(bf); if(len && (hd[len - 1] == '\n')) len--; if(len && (hd[len - 1] == '\r')) @@ -4397,7 +4397,7 @@ static CURLcode http_parse_headers(struct Curl_easy *data, while(blen && k->header) { size_t consumed; size_t hlen; - char *hd; + const char *hd; size_t unfold_len = 0; if(data->state.leading_unfold) { diff --git a/lib/http_aws_sigv4.c b/lib/http_aws_sigv4.c index 36976530f9..2205b03d09 100644 --- a/lib/http_aws_sigv4.c +++ b/lib/http_aws_sigv4.c @@ -732,7 +732,7 @@ UNITTEST CURLcode canon_query(const char *query, struct dynbuf *dq) size_t in_key_len; const char *offset; size_t query_part_len = curlx_dyn_len(&query_array[index]); - char *query_part = curlx_dyn_ptr(&query_array[index]); + const char *query_part = curlx_dyn_ptr(&query_array[index]); in_key = query_part; @@ -788,8 +788,8 @@ UNITTEST CURLcode canon_query(const char *query, struct dynbuf *dq) if(index) result = curlx_dyn_addn(dq, "&", 1); if(!result) { - char *key_ptr = curlx_dyn_ptr(&encoded_query_array[index].key); - char *value_ptr = curlx_dyn_ptr(&encoded_query_array[index].value); + const char *key_ptr = curlx_dyn_ptr(&encoded_query_array[index].key); + const char *value_ptr = curlx_dyn_ptr(&encoded_query_array[index].value); size_t vlen = curlx_dyn_len(&encoded_query_array[index].value); if(value_ptr && vlen) { result = curlx_dyn_addf(dq, "%s=%s", key_ptr, value_ptr); diff --git a/lib/http_chunks.c b/lib/http_chunks.c index c950346b2d..9b38a3780c 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -242,7 +242,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data, case CHUNK_TRAILER: if((*buf == 0x0d) || (*buf == 0x0a)) { - char *tr = curlx_dyn_ptr(&ch->trailer); + const char *tr = curlx_dyn_ptr(&ch->trailer); /* this is the end of a trailer, but if the trailer was zero bytes there was no trailer and we move on */ @@ -517,7 +517,7 @@ static CURLcode add_last_chunk(struct Curl_easy *data, for(tr = trailers; tr; tr = tr->next) { /* only add correctly formatted trailers */ - char *ptr = strchr(tr->data, ':'); + const char *ptr = strchr(tr->data, ':'); if(!ptr || *(ptr + 1) != ' ') { infof(data, "Malformatted trailing header, skipping trailer"); continue; diff --git a/lib/imap.c b/lib/imap.c index c4032a69e5..df7a54f2b4 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -1220,7 +1220,7 @@ static CURLcode imap_state_listsearch_resp(struct Curl_easy *data, imapstate instate) { CURLcode result = CURLE_OK; - char *line = curlx_dyn_ptr(&imapc->pp.recvbuf); + const char *line = curlx_dyn_ptr(&imapc->pp.recvbuf); size_t len = imapc->pp.nfinal; struct IMAP *imap = Curl_meta_get(data, CURL_META_IMAP_EASY); diff --git a/lib/ldap.c b/lib/ldap.c index bff1f0f167..3e7bbaa040 100644 --- a/lib/ldap.c +++ b/lib/ldap.c @@ -338,7 +338,7 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done) ldap_set_option(server, LDAP_OPT_SSL, LDAP_OPT_ON); #else /* !USE_WIN32_LDAP */ int ldap_option; - char *ldap_ca = conn->ssl_config.CAfile; + const char *ldap_ca = conn->ssl_config.CAfile; #ifdef LDAP_OPT_X_TLS if(conn->ssl_config.verifypeer) { /* OpenLDAP SDK supports BASE64 files. */ diff --git a/lib/mime.c b/lib/mime.c index 45a93eb3fc..a80b206d9c 100644 --- a/lib/mime.c +++ b/lib/mime.c @@ -1204,7 +1204,7 @@ curl_mime *curl_mime_init(void *easy) /* Initialize a mime part. */ void Curl_mime_initpart(curl_mimepart *part) { - memset((char *)part, 0, sizeof(*part)); + memset(part, 0, sizeof(*part)); part->lastreadstatus = 1; /* Successful read status. */ mimesetstate(&part->state, MIMESTATE_BEGIN, NULL); } diff --git a/lib/mqtt.c b/lib/mqtt.c index cabafa3383..46bfad9596 100644 --- a/lib/mqtt.c +++ b/lib/mqtt.c @@ -403,7 +403,7 @@ static CURLcode mqtt_verify_connack(struct Curl_easy *data) { struct MQTT *mq = Curl_meta_get(data, CURL_META_MQTT_EASY); CURLcode result; - char *ptr; + const char *ptr; DEBUGASSERT(mq); if(!mq) @@ -433,7 +433,7 @@ fail: static CURLcode mqtt_get_topic(struct Curl_easy *data, char **topic, size_t *topiclen) { - char *path = data->state.up.path; + const char *path = data->state.up.path; CURLcode result = CURLE_URL_MALFORMAT; if(strlen(path) > 1) { result = Curl_urldecode(path + 1, 0, topic, topiclen, REJECT_NADA); @@ -506,7 +506,7 @@ static CURLcode mqtt_verify_suback(struct Curl_easy *data) struct connectdata *conn = data->conn; struct mqtt_conn *mqtt = Curl_conn_meta_get(conn, CURL_META_MQTT_CONN); CURLcode result; - char *ptr; + const char *ptr; if(!mqtt || !mq) return CURLE_FAILED_INIT; @@ -595,7 +595,8 @@ fail: } /* return 0 on success, non-zero on error */ -static int mqtt_decode_len(size_t *lenp, unsigned char *buf, size_t buflen) +static int mqtt_decode_len(size_t *lenp, const unsigned char *buf, + size_t buflen) { size_t len = 0; size_t mult = 1; diff --git a/lib/openldap.c b/lib/openldap.c index fad8e54a90..83ae013593 100644 --- a/lib/openldap.c +++ b/lib/openldap.c @@ -337,7 +337,7 @@ static CURLcode oldap_perform_bind(struct Curl_easy *data, ldapstate newstate) { struct connectdata *conn = data->conn; struct ldapconninfo *li = Curl_conn_meta_get(conn, CURL_META_LDAP_CONN); - char *binddn = NULL; + const char *binddn = NULL; struct berval passwd; int rc; @@ -724,8 +724,9 @@ static CURLcode oldap_state_mechs_resp(struct Curl_easy *data, if(bvals) { for(i = 0; bvals[i].bv_val; i++) { size_t llen; - unsigned short mech = Curl_sasl_decode_mech((char *)bvals[i].bv_val, - bvals[i].bv_len, &llen); + unsigned short mech = + Curl_sasl_decode_mech((const char *)bvals[i].bv_val, + bvals[i].bv_len, &llen); if(bvals[i].bv_len == llen) li->sasl.authmechs |= mech; } diff --git a/lib/smtp.c b/lib/smtp.c index cb502dee82..23590398f9 100644 --- a/lib/smtp.c +++ b/lib/smtp.c @@ -1341,7 +1341,7 @@ static CURLcode smtp_state_command_resp(struct Curl_easy *data, smtpstate instate) { CURLcode result = CURLE_OK; - char *line = curlx_dyn_ptr(&smtpc->pp.recvbuf); + const char *line = curlx_dyn_ptr(&smtpc->pp.recvbuf); size_t len = smtpc->pp.nfinal; (void)instate; diff --git a/lib/socks.c b/lib/socks.c index 44a27bf1f7..43be771ad0 100644 --- a/lib/socks.c +++ b/lib/socks.c @@ -837,7 +837,7 @@ static CURLproxycode socks5_resolving(struct socks_state *sx, struct Curl_dns_entry *dns = NULL; struct Curl_addrinfo *hp = NULL; char dest[MAX_IPADR_LEN]; /* printable address */ - unsigned char *destination = NULL; + const unsigned char *destination = NULL; unsigned char desttype = 1, destlen = 4; unsigned char req[2]; CURLcode result; @@ -896,7 +896,7 @@ static CURLproxycode socks5_resolving(struct socks_state *sx, desttype = 1; /* ATYP: IPv4 = 1 */ destlen = 4; saddr_in = (struct sockaddr_in *)(void *)hp->ai_addr; - destination = (unsigned char *)&saddr_in->sin_addr.s_addr; + destination = (const unsigned char *)&saddr_in->sin_addr.s_addr; CURL_TRC_CF(data, cf, "SOCKS5 connect to %s:%d (locally resolved)", dest, sx->remote_port); } @@ -906,7 +906,7 @@ static CURLproxycode socks5_resolving(struct socks_state *sx, desttype = 4; /* ATYP: IPv6 = 4 */ destlen = 16; saddr_in6 = (struct sockaddr_in6 *)(void *)hp->ai_addr; - destination = (unsigned char *)&saddr_in6->sin6_addr.s6_addr; + destination = (const unsigned char *)&saddr_in6->sin6_addr.s6_addr; CURL_TRC_CF(data, cf, "SOCKS5 connect to [%s]:%d (locally resolved)", dest, sx->remote_port); } diff --git a/lib/socks_gssapi.c b/lib/socks_gssapi.c index 579ae71b9a..f24a338382 100644 --- a/lib/socks_gssapi.c +++ b/lib/socks_gssapi.c @@ -317,7 +317,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, } infof(data, "SOCKS5 server authenticated user %.*s with GSS-API.", - (int)gss_send_token.length, (char *)gss_send_token.value); + (int)gss_send_token.length, (const char *)gss_send_token.value); gss_release_name(&gss_status, &gss_client_name); gss_release_buffer(&gss_status, &gss_send_token); diff --git a/lib/strcase.c b/lib/strcase.c index 34ccae35de..9f70f41bd6 100644 --- a/lib/strcase.c +++ b/lib/strcase.c @@ -116,7 +116,7 @@ void Curl_strntolower(char *dest, const char *src, size_t n) /* Compare case-sensitive null-terminated strings, taking care of possible * null pointers. Return true if arguments match. */ -bool Curl_safecmp(char *a, char *b) +bool Curl_safecmp(const char *a, const char *b) { if(a && b) return !strcmp(a, b); diff --git a/lib/strcase.h b/lib/strcase.h index 3a7f126790..35f726c3ee 100644 --- a/lib/strcase.h +++ b/lib/strcase.h @@ -35,7 +35,7 @@ char Curl_raw_tolower(char in); void Curl_strntoupper(char *dest, const char *src, size_t n); void Curl_strntolower(char *dest, const char *src, size_t n); -bool Curl_safecmp(char *a, char *b); +bool Curl_safecmp(const char *a, const char *b); int Curl_timestrcmp(const char *first, const char *second); #endif /* HEADER_CURL_STRCASE_H */ diff --git a/lib/strdup.c b/lib/strdup.c index f666571e3e..e97ae35883 100644 --- a/lib/strdup.c +++ b/lib/strdup.c @@ -36,13 +36,13 @@ char *Curl_strdup(const char *str) char *newstr; if(!str) - return (char *)NULL; + return NULL; len = strlen(str) + 1; newstr = curlx_malloc(len); if(!newstr) - return (char *)NULL; + return NULL; memcpy(newstr, str, len); return newstr; diff --git a/lib/telnet.c b/lib/telnet.c index c06b7a1b1f..d1b1d8fc5e 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -496,9 +496,9 @@ static void rec_wont(struct Curl_easy *data, struct TELNET *tn, int option) } static void printsub(struct Curl_easy *data, - int direction, /* '<' or '>' */ - unsigned char *pointer, /* where suboption data is */ - size_t length) /* length of suboption data */ + int direction, /* '<' or '>' */ + const unsigned char *pointer, /* ptr to suboption data */ + size_t length) /* suboption data length */ { if(data->set.verbose) { unsigned int i = 0; @@ -611,10 +611,10 @@ static void printsub(struct Curl_easy *data, /* Escape and send a telnet data block */ static CURLcode send_telnet_data(struct Curl_easy *data, struct TELNET *tn, - char *buffer, ssize_t nread) + const char *buffer, ssize_t nread) { size_t i, outlen; - unsigned char *outbuf; + const unsigned char *outbuf; CURLcode result = CURLE_OK; size_t bytes_written; size_t total_written = 0; @@ -641,7 +641,7 @@ static CURLcode send_telnet_data(struct Curl_easy *data, } else { outlen = (size_t)nread; - outbuf = (unsigned char *)buffer; + outbuf = (const unsigned char *)buffer; } while(!result && total_written < outlen) { /* Make sure socket is writable to avoid EWOULDBLOCK condition */ @@ -676,7 +676,7 @@ static void sendsuboption(struct Curl_easy *data, ssize_t bytes_written; int err; unsigned short x, y; - unsigned char *uc1, *uc2; + const unsigned char *uc1, *uc2; struct connectdata *conn = data->conn; switch(option) { @@ -690,8 +690,8 @@ static void sendsuboption(struct Curl_easy *data, /* Window size must be sent according to the 'network order' */ x = htons(tn->subopt_wsx); y = htons(tn->subopt_wsy); - uc1 = (unsigned char *)&x; - uc2 = (unsigned char *)&y; + uc1 = (const unsigned char *)&x; + uc2 = (const unsigned char *)&y; CURL_SB_ACCUM(tn, uc1[0]); CURL_SB_ACCUM(tn, uc1[1]); CURL_SB_ACCUM(tn, uc2[0]); @@ -702,7 +702,7 @@ static void sendsuboption(struct Curl_easy *data, CURL_SB_TERM(tn); /* data suboption is now ready */ - printsub(data, '>', (unsigned char *)tn->subbuffer + 2, + printsub(data, '>', (const unsigned char *)tn->subbuffer + 2, CURL_SB_LEN(tn) - 2); /* we send the header of the suboption... */ @@ -713,7 +713,7 @@ static void sendsuboption(struct Curl_easy *data, } /* ... then the window size with the send_telnet_data() function to deal with 0xFF cases ... */ - send_telnet_data(data, tn, (char *)tn->subbuffer + 3, 4); + send_telnet_data(data, tn, (const char *)tn->subbuffer + 3, 4); /* ... and the footer */ bytes_written = swrite(conn->sock[FIRSTSOCKET], tn->subbuffer + 7, 2); if(bytes_written < 0) { @@ -986,7 +986,8 @@ static CURLcode suboption(struct Curl_easy *data, struct TELNET *tn) if(!CURL_SB_LEN(tn)) /* ignore empty suboption */ return CURLE_OK; - printsub(data, '<', (unsigned char *)tn->subbuffer, CURL_SB_LEN(tn) + 2); + printsub(data, '<', (const unsigned char *)tn->subbuffer, + CURL_SB_LEN(tn) + 2); switch(CURL_SB_GET(tn)) { case CURL_TELOPT_TTYPE: if(bad_option(tn->subopt_ttype)) diff --git a/lib/tftp.c b/lib/tftp.c index d10b6fc611..782cb1959a 100644 --- a/lib/tftp.c +++ b/lib/tftp.c @@ -1078,7 +1078,7 @@ static CURLcode tftp_receive_packet(struct Curl_easy *data, if(state->rbytes > 4 && (NEXT_BLOCKNUM(state->block) == getrpacketblock(&state->rpacket))) { result = Curl_client_write(data, CLIENTWRITE_BODY, - (char *)state->rpacket.data + 4, + (const char *)state->rpacket.data + 4, state->rbytes - 4); if(result) { tftp_state_machine(state, TFTP_EVENT_ERROR); @@ -1088,7 +1088,7 @@ static CURLcode tftp_receive_packet(struct Curl_easy *data, break; case TFTP_EVENT_ERROR: { unsigned short error = getrpacketblock(&state->rpacket); - char *str = (char *)state->rpacket.data + 4; + const char *str = (const char *)state->rpacket.data + 4; size_t strn = state->rbytes - 4; state->error = (tftp_error_t)error; if(tftp_strnlen(str, strn) < strn) diff --git a/lib/url.c b/lib/url.c index 21fe1d1acb..ddd0dc5b14 100644 --- a/lib/url.c +++ b/lib/url.c @@ -1965,7 +1965,7 @@ static char *detect_proxy(struct Curl_easy *data, * that may exist registered to the same proxy host. */ static CURLcode parse_proxy(struct Curl_easy *data, - struct connectdata *conn, char *proxy, + struct connectdata *conn, const char *proxy, long proxytype) { char *portptr = NULL; @@ -2997,7 +2997,7 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data, #ifdef USE_UNIX_SOCKETS static CURLcode resolve_unix(struct Curl_easy *data, struct connectdata *conn, - char *unix_path, + const char *unix_path, struct Curl_dns_entry **pdns) { struct Curl_dns_entry *hostaddr; @@ -3047,7 +3047,7 @@ static CURLcode resolve_server(struct Curl_easy *data, #ifdef USE_UNIX_SOCKETS { - char *unix_path = conn->unix_domain_socket; + const char *unix_path = conn->unix_domain_socket; #ifndef CURL_DISABLE_PROXY if(!unix_path && CONN_IS_PROXIED(conn) && conn->socks_proxy.host.name && diff --git a/lib/urlapi.c b/lib/urlapi.c index 1cce6aaee2..1b67d80a9d 100644 --- a/lib/urlapi.c +++ b/lib/urlapi.c @@ -336,7 +336,7 @@ UNITTEST CURLUcode Curl_parse_port(struct Curl_URL *u, struct dynbuf *host, bool has_scheme) { const char *portptr; - char *hostname = curlx_dyn_ptr(host); + const char *hostname = curlx_dyn_ptr(host); /* * Find the end of an IPv6 address on the ']' ending bracket. */ diff --git a/lib/vauth/digest.c b/lib/vauth/digest.c index 790240837b..f34db9b90f 100644 --- a/lib/vauth/digest.c +++ b/lib/vauth/digest.c @@ -130,8 +130,9 @@ bool Curl_auth_digest_get_pair(const char *str, char *value, char *content, #ifndef USE_WINDOWS_SSPI /* Convert MD5 chunk to RFC2617 (section 3.1.3) -suitable ASCII string */ -static void auth_digest_md5_to_ascii(unsigned char *source, /* 16 bytes */ - unsigned char *dest) /* 33 bytes */ +static void auth_digest_md5_to_ascii( + const unsigned char *source, /* 16 bytes */ + unsigned char *dest) /* 33 bytes */ { int i; for(i = 0; i < 16; i++) @@ -139,8 +140,9 @@ static void auth_digest_md5_to_ascii(unsigned char *source, /* 16 bytes */ } /* Convert sha256 or SHA-512/256 chunk to RFC7616 -suitable ASCII string */ -static void auth_digest_sha256_to_ascii(unsigned char *source, /* 32 bytes */ - unsigned char *dest) /* 65 bytes */ +static void auth_digest_sha256_to_ascii( + const unsigned char *source, /* 32 bytes */ + unsigned char *dest) /* 65 bytes */ { int i; for(i = 0; i < 32; i++) @@ -670,7 +672,7 @@ static CURLcode auth_create_digest_http_message( const unsigned char *uripath, struct digestdata *digest, char **outptr, size_t *outlen, - void (*convert_to_ascii)(unsigned char *, unsigned char *), + void (*convert_to_ascii)(const unsigned char *, unsigned char *), CURLcode (*hash)(unsigned char *, const unsigned char *, const size_t)) { CURLcode result; diff --git a/lib/vauth/ntlm.c b/lib/vauth/ntlm.c index fe45867b2f..21f815779a 100644 --- a/lib/vauth/ntlm.c +++ b/lib/vauth/ntlm.c @@ -565,7 +565,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data, unsigned int ntrespoff; unsigned int ntresplen = 24; unsigned char ntresp[24]; /* fixed-size */ - unsigned char *ptr_ntresp = &ntresp[0]; + const unsigned char *ptr_ntresp = &ntresp[0]; unsigned char *ntlmv2resp = NULL; bool unicode = (ntlm->flags & NTLMFLAG_NEGOTIATE_UNICODE); /* The fixed hostname we provide, in order to not leak our real local host diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index 0a86d12151..a5d58ec731 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -1367,7 +1367,7 @@ static int myssh_in_SFTP_QUOTE(struct Curl_easy *data, /* * Support some of the "FTP" commands */ - char *cmd = sshc->quote_item->data; + const char *cmd = sshc->quote_item->data; sshc->acceptfail = FALSE; /* if a command starts with an asterisk, which a legal SFTP command never @@ -1578,7 +1578,7 @@ static int myssh_in_SFTP_NEXT_QUOTE(struct Curl_easy *data, static int myssh_in_SFTP_QUOTE_STAT(struct Curl_easy *data, struct ssh_conn *sshc) { - char *cmd = sshc->quote_item->data; + const char *cmd = sshc->quote_item->data; sshc->acceptfail = FALSE; /* if a command starts with an asterisk, which a legal SFTP command never diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index cf04adcca2..7b0fbd636e 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -737,7 +737,7 @@ static CURLcode sftp_quote(struct Curl_easy *data, * 'sshc->quote_item' is already verified to be non-NULL before it * switched to this state. */ - char *cmd = sshc->quote_item->data; + const char *cmd = sshc->quote_item->data; sshc->acceptfail = FALSE; /* if a command starts with an asterisk, which a legal SFTP command never @@ -1165,7 +1165,7 @@ static CURLcode sftp_quote_stat(struct Curl_easy *data, struct SSHPROTO *sshp, bool *blockp) { - char *cmd = sshc->quote_item->data; + const char *cmd = sshc->quote_item->data; sshc->acceptfail = FALSE; /* if a command starts with an asterisk, which a legal SFTP command never diff --git a/lib/vssh/vssh.c b/lib/vssh/vssh.c index e36c703780..b52b09b696 100644 --- a/lib/vssh/vssh.c +++ b/lib/vssh/vssh.c @@ -125,7 +125,7 @@ void Curl_ssh_set_state(struct Curl_easy *data, /* figure out the path to work with in this particular request */ CURLcode Curl_getworkingpath(struct Curl_easy *data, - char *homedir, /* when SFTP is used */ + const char *homedir, /* when SFTP is used */ char **path) /* returns the allocated real path to work with */ { diff --git a/lib/vssh/vssh.h b/lib/vssh/vssh.h index f3a4873e7f..4d5b7ad24e 100644 --- a/lib/vssh/vssh.h +++ b/lib/vssh/vssh.h @@ -28,7 +28,7 @@ #include "../urldata.h" CURLcode Curl_getworkingpath(struct Curl_easy *data, - char *homedir, + const char *homedir, char **path); CURLcode Curl_get_pathname(const char **cpp, char **path, const char *homedir); diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c index e4f910b85c..e7e412b488 100644 --- a/lib/vtls/vtls.c +++ b/lib/vtls/vtls.c @@ -1058,7 +1058,7 @@ static size_t multissl_version(char *buffer, size_t size) if(current != selected) { char *p = backends; - char *end = backends + sizeof(backends); + const char *end = backends + sizeof(backends); int i; selected = current; diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c index 1225063c99..750f1123a5 100644 --- a/lib/vtls/wolfssl.c +++ b/lib/vtls/wolfssl.c @@ -1135,7 +1135,7 @@ CURLcode Curl_wssl_ctx_init(struct wssl_ctx *wctx, #ifndef WOLFSSL_TLS13 { - char *ciphers = conn_config->cipher_list; + const char *ciphers = conn_config->cipher_list; if(ciphers) { if(!SSL_CTX_set_cipher_list(wctx->ssl_ctx, ciphers)) { failf(data, "failed setting cipher list: %s", ciphers); diff --git a/lib/vtls/x509asn1.c b/lib/vtls/x509asn1.c index e6fdb10d65..5c3a727e63 100644 --- a/lib/vtls/x509asn1.c +++ b/lib/vtls/x509asn1.c @@ -146,7 +146,7 @@ static const struct Curl_OID OIDtable[] = { { "2.16.840.1.101.3.4.2.2", "sha384" }, { "2.16.840.1.101.3.4.2.3", "sha512" }, { "1.2.840.113549.1.9.2", "unstructuredName" }, - { (const char *)NULL, (const char *)NULL } + { NULL, NULL } }; #endif /* WANT_EXTRACT_CERTINFO */ @@ -932,7 +932,7 @@ static CURLcode ssl_push_certinfo_dyn(struct Curl_easy *data, struct dynbuf *ptr) { size_t valuelen = curlx_dyn_len(ptr); - char *value = curlx_dyn_ptr(ptr); + const char *value = curlx_dyn_ptr(ptr); CURLcode result = Curl_ssl_push_certinfo_len(data, certnum, label, value, valuelen); diff --git a/src/curlinfo.c b/src/curlinfo.c index b5626232e3..0a6c7fc135 100644 --- a/src/curlinfo.c +++ b/src/curlinfo.c @@ -257,7 +257,7 @@ static const char *disabled[] = { #endif }; -int main(int argc, char **argv) +int main(int argc, const char **argv) { size_t i; diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c index eb35c5c383..c50fac6b32 100644 --- a/src/tool_cb_hdr.c +++ b/src/tool_cb_hdr.c @@ -66,8 +66,8 @@ static void write_linked_location(CURL *curl, const char *location, { /* This would so simple if CURLINFO_REDIRECT_URL were available here */ CURLU *u = NULL; - char *copyloc = NULL, *locurl = NULL, *scheme = NULL, *finalurl = NULL; - const char *loc = location; + char *copyloc = NULL, *scheme = NULL, *finalurl = NULL; + const char *loc = location, *locurl = NULL; size_t llen = loclen; int space_skipped = 0; const char *vver = getenv("VTE_VERSION"); diff --git a/src/tool_helpers.c b/src/tool_helpers.c index c32e1bbaab..2a84accf2c 100644 --- a/src/tool_helpers.c +++ b/src/tool_helpers.c @@ -96,7 +96,7 @@ int SetHTTPrequest(HttpReq req, HttpReq *store) return 1; } -void customrequest_helper(HttpReq req, char *method) +void customrequest_helper(HttpReq req, const char *method) { /* this mirrors the HttpReq enum in tool_sdecls.h */ const char *dflt[] = { diff --git a/src/tool_helpers.h b/src/tool_helpers.h index fab026b05d..cbfa168523 100644 --- a/src/tool_helpers.h +++ b/src/tool_helpers.h @@ -27,6 +27,6 @@ const char *param2text(ParameterError error); int SetHTTPrequest(HttpReq req, HttpReq *store); -void customrequest_helper(HttpReq req, char *method); +void customrequest_helper(HttpReq req, const char *method); #endif /* HEADER_CURL_TOOL_HELPERS_H */ diff --git a/src/tool_operate.c b/src/tool_operate.c index 300826ef26..8eea688b02 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -1753,7 +1753,7 @@ static CURLcode check_finished(struct parastate *s) struct per_transfer *ended; CURL *easy = msg->easy_handle; CURLcode tres = msg->data.result; - curl_easy_getinfo(easy, CURLINFO_PRIVATE, (void *)&ended); + curl_easy_getinfo(easy, CURLINFO_PRIVATE, &ended); curl_multi_remove_handle(s->multi, easy); if(ended->abort && (tres == CURLE_ABORTED_BY_CALLBACK)) { @@ -2022,7 +2022,7 @@ static CURLcode is_using_schannel(int *pusing) if(using_schannel == -1) { CURL *curltls = curl_easy_init(); /* The TLS backend remains, so keep the info */ - struct curl_tlssessioninfo *tls_backend_info = NULL; + const struct curl_tlssessioninfo *tls_backend_info = NULL; if(!curltls) result = CURLE_OUT_OF_MEMORY; diff --git a/src/tool_operate.h b/src/tool_operate.h index 8c30d3b651..93c87e10e6 100644 --- a/src/tool_operate.h +++ b/src/tool_operate.h @@ -34,7 +34,7 @@ struct per_transfer { struct per_transfer *next; struct per_transfer *prev; struct OperationConfig *config; /* for this transfer */ - struct curl_certinfo *certinfo; + const struct curl_certinfo *certinfo; CURL *curl; long retry_remaining; long retry_sleep_default; diff --git a/src/tool_parsecfg.c b/src/tool_parsecfg.c index ae206f8d51..b36d113232 100644 --- a/src/tool_parsecfg.c +++ b/src/tool_parsecfg.c @@ -277,7 +277,7 @@ static bool get_line(FILE *input, struct dynbuf *buf, bool *error) char buffer[128]; curlx_dyn_reset(buf); while(1) { - char *b = fgets(buffer, sizeof(buffer), input); + const char *b = fgets(buffer, sizeof(buffer), input); if(b) { size_t rlen = strlen(b); diff --git a/src/tool_writeout.c b/src/tool_writeout.c index fbb8a4fb5e..2700abfa44 100644 --- a/src/tool_writeout.c +++ b/src/tool_writeout.c @@ -86,7 +86,7 @@ static int urlpart(struct per_transfer *per, writeoutid vid, if(uh) { CURLUPart cpart = CURLUPART_HOST; char *part = NULL; - const char *url = NULL; + char *url = NULL; if(vid >= VAR_INPUT_URLESCHEME) { if(curl_easy_getinfo(per->curl, CURLINFO_EFFECTIVE_URL, &url)) @@ -162,7 +162,7 @@ static int urlpart(struct per_transfer *per, writeoutid vid, static void certinfo(struct per_transfer *per) { if(!per->certinfo) { - struct curl_certinfo *certinfo; + const struct curl_certinfo *certinfo; CURLcode result = curl_easy_getinfo(per->curl, CURLINFO_CERTINFO, &certinfo); per->certinfo = (!result && certinfo) ? certinfo : NULL; diff --git a/tests/cmake/test.c b/tests/cmake/test.c index 66cf4b8fb7..e8d1209ac5 100644 --- a/tests/cmake/test.c +++ b/tests/cmake/test.c @@ -24,7 +24,7 @@ #include "curl/curl.h" #include -int main(int argc, char **argv) +int main(int argc, const char **argv) { (void)argc; puts("libcurl test:"); diff --git a/tests/libtest/cli_h2_serverpush.c b/tests/libtest/cli_h2_serverpush.c index 31e07aa427..8a16b01eba 100644 --- a/tests/libtest/cli_h2_serverpush.c +++ b/tests/libtest/cli_h2_serverpush.c @@ -60,7 +60,7 @@ static int server_push_callback(CURL *parent, struct curl_pushheaders *headers, void *userp) { - char *headp; + const char *headp; size_t i; int *transfers = (int *)userp; char filename[128]; diff --git a/tests/libtest/cli_hx_download.c b/tests/libtest/cli_hx_download.c index 500242a7eb..5a37fcbab3 100644 --- a/tests/libtest/cli_hx_download.c +++ b/tests/libtest/cli_hx_download.c @@ -211,7 +211,7 @@ static int my_progress_d_cb(void *userdata, static int setup_hx_download(CURL *curl, const char *url, struct transfer_d *t, long http_version, struct curl_slist *host, CURLSH *share, int use_earlydata, - int fresh_connect, char *cafile) + int fresh_connect, const char *cafile) { curl_easy_setopt(curl, CURLOPT_SHARE, share); curl_easy_setopt(curl, CURLOPT_URL, url); diff --git a/tests/libtest/lib1518.c b/tests/libtest/lib1518.c index 3320a983ca..f6fe44c5e9 100644 --- a/tests/libtest/lib1518.c +++ b/tests/libtest/lib1518.c @@ -41,8 +41,8 @@ static CURLcode test_lib1518(const char *URL) CURLcode result = CURLE_OK; long curlResponseCode; long curlRedirectCount; - char *effectiveUrl = NULL; - char *redirectUrl = NULL; + const char *effectiveUrl = NULL; + const char *redirectUrl = NULL; CURLU *urlu = NULL; curl = curl_easy_init(); if(!curl) { diff --git a/tests/libtest/lib1536.c b/tests/libtest/lib1536.c index 7f2e415414..9debd78807 100644 --- a/tests/libtest/lib1536.c +++ b/tests/libtest/lib1536.c @@ -28,7 +28,7 @@ static CURLcode test_lib1536(const char *URL) { CURL *curl, *dupe = NULL; - char *scheme; + const char *scheme; CURLcode result = CURLE_OK; global_init(CURL_GLOBAL_ALL); diff --git a/tests/libtest/lib1560.c b/tests/libtest/lib1560.c index c880902940..1b329f7cfd 100644 --- a/tests/libtest/lib1560.c +++ b/tests/libtest/lib1560.c @@ -1150,7 +1150,7 @@ static const struct setcase set_parts_list[] = { {NULL, NULL, NULL, 0, 0, CURLUE_OK, CURLUE_OK} }; -static CURLUPart part2id(char *part) +static CURLUPart part2id(const char *part) { if(!strcmp("url", part)) return CURLUPART_URL; diff --git a/tests/libtest/lib1977.c b/tests/libtest/lib1977.c index 5813cca4ea..608ba4e8b6 100644 --- a/tests/libtest/lib1977.c +++ b/tests/libtest/lib1977.c @@ -29,7 +29,7 @@ static CURLcode test_lib1977(const char *URL) CURLU *curlu = curl_url(); CURLU *curlu_2 = curl_url(); CURL *curl; - char *effective = NULL; + const char *effective = NULL; global_init(CURL_GLOBAL_ALL); easy_init(curl); diff --git a/tests/libtest/lib3010.c b/tests/libtest/lib3010.c index 5c7104a414..7a668b0751 100644 --- a/tests/libtest/lib3010.c +++ b/tests/libtest/lib3010.c @@ -28,7 +28,7 @@ static CURLcode test_lib3010(const char *URL) CURLcode result = TEST_ERR_MAJOR_BAD; CURL *curl = NULL; curl_off_t retry_after; - char *follow_url = NULL; + const char *follow_url = NULL; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); diff --git a/tests/libtest/lib3102.c b/tests/libtest/lib3102.c index 8313d54be0..90095adc2b 100644 --- a/tests/libtest/lib3102.c +++ b/tests/libtest/lib3102.c @@ -29,7 +29,7 @@ */ static bool is_chain_in_order(struct curl_certinfo *cert_info) { - char *last_issuer = NULL; + const char *last_issuer = NULL; int cert; /* Chains with only a single certificate are always in order */ @@ -39,8 +39,8 @@ static bool is_chain_in_order(struct curl_certinfo *cert_info) /* Enumerate each certificate in the chain */ for(cert = 0; cert < cert_info->num_of_certs; cert++) { struct curl_slist *slist = cert_info->certinfo[cert]; - char *issuer = NULL; - char *subject = NULL; + const char *issuer = NULL; + const char *subject = NULL; /* Find the certificate issuer and subject by enumerating each field */ for(; slist && (!issuer || !subject); slist = slist->next) { diff --git a/tests/libtest/lib3207.c b/tests/libtest/lib3207.c index 7b8f947df6..c764add27f 100644 --- a/tests/libtest/lib3207.c +++ b/tests/libtest/lib3207.c @@ -46,7 +46,7 @@ static size_t write_memory_callback(char *contents, size_t size, /* append the data to contents */ size_t realsize = size * nmemb; struct Ctx *mem = (struct Ctx *)userp; - char *data = (char *)curlx_malloc(realsize + 1); + char *data = curlx_malloc(realsize + 1); struct curl_slist *item_append = NULL; if(!data) { curl_mprintf("not enough memory (malloc returned NULL)\n"); diff --git a/tests/libtest/lib500.c b/tests/libtest/lib500.c index 7930220314..71b1eaed8f 100644 --- a/tests/libtest/lib500.c +++ b/tests/libtest/lib500.c @@ -55,7 +55,7 @@ static CURLcode test_lib500(const char *URL) { CURLcode result; CURL *curl; - char *ipstr = NULL; + const char *ipstr = NULL; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { curl_mfprintf(stderr, "curl_global_init() failed\n"); diff --git a/tests/libtest/lib569.c b/tests/libtest/lib569.c index 211dd6bcc1..e29b7d71ee 100644 --- a/tests/libtest/lib569.c +++ b/tests/libtest/lib569.c @@ -33,7 +33,6 @@ static CURLcode test_lib569(const char *URL) CURLcode result; CURL *curl; char *stream_uri = NULL; - char *rtsp_session_id; int request = 1; int i; @@ -74,6 +73,7 @@ static CURLcode test_lib569(const char *URL) /* Go through the various Session IDs */ for(i = 0; i < 3; i++) { + const char *rtsp_session_id; stream_uri = tutil_suburl(URL, request++); if(!stream_uri) { result = TEST_ERR_MAJOR_BAD; diff --git a/tests/libtest/mk-lib1521.pl b/tests/libtest/mk-lib1521.pl index 0a0c48b2f2..3430ca1f19 100755 --- a/tests/libtest/mk-lib1521.pl +++ b/tests/libtest/mk-lib1521.pl @@ -209,7 +209,7 @@ print $fh <
-int main(int argc, char **argv) +int main(int argc, const char **argv) { entry_func_t entry_func; - char *entry_name; + const char *entry_name; size_t tmp; if(argc < 2) { diff --git a/tests/server/first.h b/tests/server/first.h index 0d0dc30a0e..1de25f6863 100644 --- a/tests/server/first.h +++ b/tests/server/first.h @@ -39,7 +39,7 @@ #include "curl_setup.h" -typedef int (*entry_func_t)(int, char **); +typedef int (*entry_func_t)(int, const char **); struct entry_s { const char *name; @@ -125,9 +125,8 @@ extern int getpart(char **outbuf, size_t *outlen, const char *main, const char *sub, FILE *stream); /* utility functions */ -extern char *data_to_hex(char *data, size_t len); extern void logmsg(const char *msg, ...) CURL_PRINTF(1, 2); -extern void loghex(unsigned char *buffer, ssize_t len); +extern void loghex(const unsigned char *buffer, ssize_t len); extern int win32_init(void); extern FILE *test2fopen(long testno, const char *logdir2); extern curl_off_t our_getpid(void); diff --git a/tests/server/getpart.c b/tests/server/getpart.c index 9a9c12a38d..2f276e0ad5 100644 --- a/tests/server/getpart.c +++ b/tests/server/getpart.c @@ -141,12 +141,13 @@ static int readline(char **buffer, size_t *bufsize, size_t *length, * GPE_OUT_OF_MEMORY * GPE_OK */ -static int appenddata(char **dst_buf, /* dest buffer */ - size_t *dst_len, /* dest buffer data length */ - size_t *dst_alloc, /* dest buffer allocated size */ - char *src_buf, /* source buffer */ - size_t src_len, /* source buffer length */ - int src_b64) /* != 0 if source is base64 encoded */ +static int appenddata(char **dst_buf, /* dest buffer */ + size_t *dst_len, /* dest buffer data length */ + size_t *dst_alloc, /* dest buffer allocated size */ + const char *src_buf, /* source buffer */ + size_t src_len, /* source buffer length */ + int src_b64) /* != 0 if source is base64 + encoded */ { size_t need_alloc = 0; @@ -182,7 +183,7 @@ static int appenddata(char **dst_buf, /* dest buffer */ return GPE_OK; } -static int decodedata(char **buf, /* dest buffer */ +static int decodedata(char **buf, /* dest buffer */ size_t *len) /* dest buffer data length */ { CURLcode result = CURLE_OK; diff --git a/tests/server/mqttd.c b/tests/server/mqttd.c index eca4cb3f7a..3e50b351df 100644 --- a/tests/server/mqttd.c +++ b/tests/server/mqttd.c @@ -131,11 +131,11 @@ typedef enum { static void logprotocol(mqttdir dir, const char *prefix, size_t remlen, FILE *output, - unsigned char *buffer, ssize_t len) + const unsigned char *buffer, ssize_t len) { char data[12000] = ""; ssize_t i; - unsigned char *ptr = buffer; + const unsigned char *ptr = buffer; char *optr = data; int left = sizeof(data); @@ -279,7 +279,7 @@ static size_t encode_length(size_t packetlen, return bytes; } -static size_t decode_length(unsigned char *buffer, +static size_t decode_length(const unsigned char *buffer, size_t buflen, size_t *lenbytes) { size_t len = 0; @@ -712,7 +712,7 @@ static bool mqttd_incoming(curl_socket_t listenfd) return TRUE; } -static int test_mqttd(int argc, char *argv[]) +static int test_mqttd(int argc, const char *argv[]) { curl_socket_t sock = CURL_SOCKET_BAD; curl_socket_t msgsock = CURL_SOCKET_BAD; diff --git a/tests/server/resolve.c b/tests/server/resolve.c index 3abcbcb33d..ac72cddd3a 100644 --- a/tests/server/resolve.c +++ b/tests/server/resolve.c @@ -33,7 +33,7 @@ * */ -static int test_resolve(int argc, char *argv[]) +static int test_resolve(int argc, const char *argv[]) { int arg = 1; const char *host = NULL; diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c index c3878ea67a..69074fb769 100644 --- a/tests/server/rtspd.c +++ b/tests/server/rtspd.c @@ -143,7 +143,7 @@ static const char *RTP_DATA = "$_1234\n\0Rsdf"; static int rtspd_ProcessRequest(struct rtspd_httprequest *req) { - char *line = &req->reqbuf[req->checkindex]; + const char *line = &req->reqbuf[req->checkindex]; bool chunked = FALSE; static char request[REQUEST_KEYWORD_SIZE]; static char doc[MAXDOCNAMELEN]; @@ -539,7 +539,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req) } /* store the entire request in a file */ -static void rtspd_storerequest(char *reqbuf, size_t totalsize) +static void rtspd_storerequest(const char *reqbuf, size_t totalsize) { int res; int error = 0; @@ -997,7 +997,7 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req) return 0; } -static int test_rtspd(int argc, char *argv[]) +static int test_rtspd(int argc, const char *argv[]) { srvr_sockaddr_union_t me; curl_socket_t sock = CURL_SOCKET_BAD; diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c index 9d132b9392..008c37234d 100644 --- a/tests/server/sockfilt.c +++ b/tests/server/sockfilt.c @@ -313,11 +313,11 @@ static bool write_stdout(const void *buffer, size_t nbytes) return TRUE; } -static void lograw(unsigned char *buffer, ssize_t len) +static void lograw(const unsigned char *buffer, ssize_t len) { char data[120]; ssize_t i; - unsigned char *ptr = buffer; + const unsigned char *ptr = buffer; char *optr = data; ssize_t width = 0; int left = sizeof(data); @@ -372,7 +372,7 @@ static bool read_data_block(unsigned char *buffer, ssize_t maxlen, buffer[5] = '\0'; - endp = (char *)buffer; + endp = (const char *)buffer; if(curlx_str_hex(&endp, &value, 0xfffff)) { logmsg("Failed to decode buffer size"); return FALSE; @@ -1066,7 +1066,7 @@ static bool juggle(curl_socket_t *sockfdp, Replies to PORT with "IPv[num]/[port]" */ snprintf((char *)buffer, sizeof(buffer), "%s/%hu\n", ipv_inuse, server_port); - buffer_len = (ssize_t)strlen((char *)buffer); + buffer_len = (ssize_t)strlen((const char *)buffer); snprintf(data, sizeof(data), "PORT\n%04x\n", (int)buffer_len); if(!write_stdout(data, 10)) return FALSE; @@ -1171,7 +1171,7 @@ static bool juggle(curl_socket_t *sockfdp, return TRUE; } -static int test_sockfilt(int argc, char *argv[]) +static int test_sockfilt(int argc, const char *argv[]) { srvr_sockaddr_union_t me; curl_socket_t sock = CURL_SOCKET_BAD; diff --git a/tests/server/socksd.c b/tests/server/socksd.c index 9875a2b7a9..783cbd16ba 100644 --- a/tests/server/socksd.c +++ b/tests/server/socksd.c @@ -238,7 +238,7 @@ static curl_socket_t socksconnect(unsigned short connectport, } static curl_socket_t socks4(curl_socket_t fd, - unsigned char *buffer, + const unsigned char *buffer, ssize_t rc) { unsigned char response[256 + 16]; @@ -299,7 +299,7 @@ static curl_socket_t sockit(curl_socket_t fd) unsigned char len; unsigned char type; unsigned char rep = 0; - unsigned char *address; + const unsigned char *address; unsigned short socksport; curl_socket_t connfd = CURL_SOCKET_BAD; unsigned short s5port; @@ -502,7 +502,7 @@ static curl_socket_t sockit(curl_socket_t fd) } if(!s_config.port) { - unsigned char *portp = &buffer[SOCKS5_DSTADDR + len]; + const unsigned char *portp = &buffer[SOCKS5_DSTADDR + len]; s5port = (unsigned short)((portp[0] << 8) | (portp[1])); } else @@ -726,7 +726,7 @@ static bool socksd_incoming(curl_socket_t listenfd) return TRUE; } -static int test_socksd(int argc, char *argv[]) +static int test_socksd(int argc, const char *argv[]) { curl_socket_t sock = CURL_SOCKET_BAD; curl_socket_t msgsock = CURL_SOCKET_BAD; diff --git a/tests/server/sws.c b/tests/server/sws.c index 297cd58174..919d16f816 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -156,6 +156,33 @@ static const char *doc404 = "


" SWSVERSION "
\n" "\n"; +/* This function returns a pointer to STATIC memory. It converts the given + * binary lump to a hex formatted string usable for output in logs or + * whatever. + */ +static char *data_to_hex(const char *data, size_t len) +{ + static char buf[256 * 3]; + size_t i; + char *optr = buf; + const char *iptr = data; + + if(len > 255) + len = 255; + + for(i = 0; i < len; i++) { + if((data[i] >= 0x20) && (data[i] < 0x7f)) + *optr++ = *iptr++; + else { + snprintf(optr, 4, "%%%02x", (unsigned char)*iptr++); + optr += 3; + } + } + *optr = 0; /* in case no sprintf was used */ + + return buf; +} + /* work around for handling trailing headers */ static int already_recv_zeroed_chunk = FALSE; @@ -303,7 +330,7 @@ static int sws_parse_servercmd(struct sws_httprequest *req) static int sws_ProcessRequest(struct sws_httprequest *req) { - char *line = &req->reqbuf[req->checkindex]; + const char *line = &req->reqbuf[req->checkindex]; bool chunked = FALSE; static char request[REQUEST_KEYWORD_SIZE]; int prot_major = 0; @@ -331,7 +358,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req) else if(req->testno == DOCNUMBER_NOTHING) { const char *http; bool fine = FALSE; - char *httppath = NULL; + const char *httppath = NULL; size_t npath = 0; /* httppath length */ if(sscanf(line, "%" REQUEST_KEYWORD_SIZE_TXT "s ", request) == 1) { @@ -357,7 +384,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req) } if(fine) { - char *ptr; + const char *ptr; req->prot_version = prot_major * 10 + prot_minor; @@ -476,7 +503,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req) sws_parse_servercmd(req); } else if((req->offset >= 3)) { - unsigned char *l = (unsigned char *)line; + const unsigned char *l = (const unsigned char *)line; logmsg("** Unusual request. Starts with %02x %02x %02x (%c%c%c)", l[0], l[1], l[2], l[0], l[1], l[2]); } @@ -1934,7 +1961,7 @@ static int service_connection(curl_socket_t *msgsock, return -1; } -static int test_sws(int argc, char *argv[]) +static int test_sws(int argc, const char *argv[]) { srvr_sockaddr_union_t me; curl_socket_t sock = CURL_SOCKET_BAD; diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index ff894bd430..91e1b7f7bb 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -111,14 +111,14 @@ struct tftphdr { *****************************************************************************/ struct testcase { - char *buffer; /* holds the file data to send to the client */ - size_t bufsize; /* size of the data in buffer */ - char *rptr; /* read pointer into the buffer */ - size_t rcount; /* amount of data left to read of the file */ - long testno; /* test case number */ - int ofile; /* file descriptor for output file when uploading to us */ - - int writedelay; /* number of seconds between each packet */ + char *buffer; /* holds the file data to send to the client */ + size_t bufsize; /* size of the data in buffer */ + const char *rptr; /* read pointer into the buffer */ + size_t rcount; /* amount of data left to read of the file */ + long testno; /* test case number */ + int ofile; /* file descriptor for output file when uploading to us */ + + int writedelay; /* number of seconds between each packet */ }; struct formats { @@ -889,7 +889,8 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size) char *cp; int first = 1, ecode; const struct formats *pf; - char *filename, *mode = NULL; + const char *filename; + char *mode = NULL; #ifdef USE_WINSOCK DWORD recvtimeout, recvtimeoutbak; #endif @@ -1004,7 +1005,7 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size) return 0; } -static int test_tftpd(int argc, char **argv) +static int test_tftpd(int argc, const char **argv) { srvr_sockaddr_union_t me; struct tftphdr *tp; diff --git a/tests/server/util.c b/tests/server/util.c index 880fd90146..41fa39c619 100644 --- a/tests/server/util.c +++ b/tests/server/util.c @@ -33,38 +33,11 @@ #include #endif -/* This function returns a pointer to STATIC memory. It converts the given - * binary lump to a hex formatted string usable for output in logs or - * whatever. - */ -char *data_to_hex(char *data, size_t len) -{ - static char buf[256 * 3]; - size_t i; - char *optr = buf; - char *iptr = data; - - if(len > 255) - len = 255; - - for(i = 0; i < len; i++) { - if((data[i] >= 0x20) && (data[i] < 0x7f)) - *optr++ = *iptr++; - else { - snprintf(optr, 4, "%%%02x", (unsigned char)*iptr++); - optr += 3; - } - } - *optr = 0; /* in case no sprintf was used */ - - return buf; -} - -void loghex(unsigned char *buffer, ssize_t len) +void loghex(const unsigned char *buffer, ssize_t len) { char data[12000]; ssize_t i; - unsigned char *ptr = buffer; + const unsigned char *ptr = buffer; char *optr = data; ssize_t width = 0; int left = sizeof(data); diff --git a/tests/unit/unit1302.c b/tests/unit/unit1302.c index 3b0d2bf2b5..32f77f1926 100644 --- a/tests/unit/unit1302.c +++ b/tests/unit/unit1302.c @@ -125,7 +125,7 @@ static CURLcode test_unit1302(const char *arg) }; for(i = 0; i < CURL_ARRAYSIZE(encode); i++) { - struct etest *e = &encode[i]; + const struct etest *e = &encode[i]; char *out; unsigned char *decoded; size_t olen; @@ -164,7 +164,7 @@ static CURLcode test_unit1302(const char *arg) } for(i = 0; i < CURL_ARRAYSIZE(url); i++) { - struct etest *e = &url[i]; + const struct etest *e = &url[i]; char *out; size_t olen; result = curlx_base64url_encode((const uint8_t *)e->input, e->ilen, diff --git a/tests/unit/unit1600.c b/tests/unit/unit1600.c index ce99379d6b..4b53b4e36b 100644 --- a/tests/unit/unit1600.c +++ b/tests/unit/unit1600.c @@ -54,7 +54,8 @@ static CURLcode test_unit1600(const char *arg) #if defined(USE_NTLM) && \ (!defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO)) unsigned char output[21]; - unsigned char *testp = output; + const unsigned char *testp = output; + Curl_ntlm_core_mk_nt_hash("1", output); verify_memory(testp, diff --git a/tests/unit/unit1601.c b/tests/unit/unit1601.c index 9b0b38486f..1e3cf096be 100644 --- a/tests/unit/unit1601.c +++ b/tests/unit/unit1601.c @@ -35,7 +35,7 @@ static CURLcode test_unit1601(const char *arg) static const char string1[] = "1"; static const char string2[] = "hello-you-fool"; unsigned char output[MD5_DIGEST_LEN]; - unsigned char *testp = output; + const unsigned char *testp = output; Curl_md5it(output, (const unsigned char *)string1, strlen(string1)); diff --git a/tests/unit/unit1603.c b/tests/unit/unit1603.c index 81db398cb1..ed6be10516 100644 --- a/tests/unit/unit1603.c +++ b/tests/unit/unit1603.c @@ -66,7 +66,7 @@ static CURLcode test_unit1603(const char *arg) char key3[] = "key3"; char key4[] = "key4"; char notakey[] = "notakey"; - char *nodep; + const char *nodep; int rc; /* Ensure the key hashes are as expected in order to test both hash diff --git a/tests/unit/unit1610.c b/tests/unit/unit1610.c index 346b0a5494..a46b7d965b 100644 --- a/tests/unit/unit1610.c +++ b/tests/unit/unit1610.c @@ -42,7 +42,7 @@ static CURLcode test_unit1610(const char *arg) static const char string1[] = "1"; static const char string2[] = "hello-you-fool"; unsigned char output[CURL_SHA256_DIGEST_LENGTH]; - unsigned char *testp = output; + const unsigned char *testp = output; Curl_sha256it(output, (const unsigned char *)string1, strlen(string1)); diff --git a/tests/unit/unit1611.c b/tests/unit/unit1611.c index fbff7f9211..2b483dbd6c 100644 --- a/tests/unit/unit1611.c +++ b/tests/unit/unit1611.c @@ -33,7 +33,7 @@ static CURLcode test_unit1611(const char *arg) static const char string1[] = "1"; static const char string2[] = "hello-you-fool"; unsigned char output[MD4_DIGEST_LENGTH]; - unsigned char *testp = output; + const unsigned char *testp = output; Curl_md4it(output, (const unsigned char *)string1, strlen(string1)); diff --git a/tests/unit/unit1612.c b/tests/unit/unit1612.c index 313ca0f329..dd6f9e0fc0 100644 --- a/tests/unit/unit1612.c +++ b/tests/unit/unit1612.c @@ -37,7 +37,7 @@ static CURLcode test_unit1612(const char *arg) static const char string1[] = "1"; static const char string2[] = "hello-you-fool"; unsigned char output[HMAC_MD5_LENGTH]; - unsigned char *testp = output; + const unsigned char *testp = output; Curl_hmacit(&Curl_HMAC_MD5, (const unsigned char *)password, strlen(password), diff --git a/tests/unit/unit1615.c b/tests/unit/unit1615.c index 93237db274..cfb1997f1c 100644 --- a/tests/unit/unit1615.c +++ b/tests/unit/unit1615.c @@ -109,7 +109,7 @@ static CURLcode test_unit1615(const char *arg) }; unsigned char output_buf[CURL_SHA512_256_DIGEST_LENGTH]; - unsigned char *computed_hash; /* Just to mute compiler warning */ + const unsigned char *computed_hash; /* Just to mute compiler warning */ /* Mute compiler warnings in 'verify_memory' macros below */ computed_hash = output_buf; diff --git a/tests/unit/unit1650.c b/tests/unit/unit1650.c index c9bb5745c7..8c979cac58 100644 --- a/tests/unit/unit1650.c +++ b/tests/unit/unit1650.c @@ -224,10 +224,11 @@ static CURLcode test_unit1650(const char *arg) ptr += o; } de_cleanup(&d); - if(resp[i].out && strcmp((char *)buffer, resp[i].out)) { + if(resp[i].out && strcmp((const char *)buffer, resp[i].out)) { curl_mfprintf(stderr, "resp %zu: Expected %s got %s\n", i, resp[i].out, buffer); - abort_if(resp[i].out && strcmp((char *)buffer, resp[i].out), "content"); + abort_if(resp[i].out && strcmp((const char *)buffer, resp[i].out), + "content"); } } @@ -271,9 +272,9 @@ static CURLcode test_unit1650(const char *arg) p = &a->ip.v4[0]; curl_msnprintf((char *)buffer, sizeof(buffer), "%u.%u.%u.%u", p[0], p[1], p[2], p[3]); - if(rc || strcmp((char *)buffer, "127.0.0.1")) { + if(rc || strcmp((const char *)buffer, "127.0.0.1")) { curl_mfprintf(stderr, "bad address decoded: %s, rc == %d\n", buffer, rc); - abort_if(rc || strcmp((char *)buffer, "127.0.0.1"), "bad address"); + abort_if(rc || strcmp((const char *)buffer, "127.0.0.1"), "bad address"); } fail_if(d.numcname, "bad cname counter"); } diff --git a/tests/unit/unit1653.c b/tests/unit/unit1653.c index 7ea7e380a8..4c9c03d9cb 100644 --- a/tests/unit/unit1653.c +++ b/tests/unit/unit1653.c @@ -27,7 +27,7 @@ #include "curl/urlapi.h" #include "urlapi-int.h" -static CURLUcode parse_port(CURLU *url, char *h, bool has_scheme) +static CURLUcode parse_port(CURLU *url, const char *h, bool has_scheme) { struct dynbuf host; CURLUcode ret; diff --git a/tests/unit/unit1658.c b/tests/unit/unit1658.c index 067bd53900..e7f753a4d0 100644 --- a/tests/unit/unit1658.c +++ b/tests/unit/unit1658.c @@ -52,7 +52,7 @@ static char rrbuffer[256]; static void rrresults(struct Curl_https_rrinfo *rr, CURLcode res) { char *p = rrbuffer; - char *pend = rrbuffer + sizeof(rrbuffer); + const char *pend = rrbuffer + sizeof(rrbuffer); curl_msnprintf(rrbuffer, sizeof(rrbuffer), "r:%d|", (int)res); p += strlen(rrbuffer); diff --git a/tests/unit/unit1979.c b/tests/unit/unit1979.c index 796099d592..943abfed65 100644 --- a/tests/unit/unit1979.c +++ b/tests/unit/unit1979.c @@ -109,7 +109,7 @@ static CURLcode test_unit1979(const char *arg) struct dynbuf canonical_path; char buffer[1024]; - char *canonical_path_string; + const char *canonical_path_string; int result; int msnprintf_result; diff --git a/tests/unit/unit1980.c b/tests/unit/unit1980.c index 82bea8415a..9fa10c538c 100644 --- a/tests/unit/unit1980.c +++ b/tests/unit/unit1980.c @@ -82,7 +82,7 @@ static CURLcode test_unit1980(const char *arg) struct dynbuf canonical_query; char buffer[1024]; - char *canonical_query_ptr; + const char *canonical_query_ptr; int result; int msnprintf_result; diff --git a/tests/unit/unit3200.c b/tests/unit/unit3200.c index 46c9b13a3f..8c808bd64b 100644 --- a/tests/unit/unit3200.c +++ b/tests/unit/unit3200.c @@ -80,7 +80,7 @@ static CURLcode test_unit3200(const char *arg) FILE *fp; struct dynbuf buf; size_t len = 4096; - char *line; + const char *line; bool eof; curlx_dyn_init(&buf, len); diff --git a/tests/unit/unit3205.c b/tests/unit/unit3205.c index f4d9ab82da..aa2d6b94a3 100644 --- a/tests/unit/unit3205.c +++ b/tests/unit/unit3205.c @@ -562,11 +562,11 @@ static CURLcode test_unit3205(const char *arg) if(test->id >= 0x0011 && test->id < 0x0017) { if(expect && memcmp(expect, "EDH-", 4) == 0) { curlx_strcopy(alt, sizeof(alt), expect, strlen(expect)); - expect = (char *)memcpy(alt, "DHE-", 4); + expect = (const char *)memcpy(alt, "DHE-", 4); } if(expect && memcmp(expect + 4, "EDH-", 4) == 0) { curlx_strcopy(alt, sizeof(alt), expect, strlen(expect)); - expect = (char *)memcpy(alt + 4, "DHE-", 4) - 4; + expect = (const char *)memcpy(alt + 4, "DHE-", 4) - 4; } }