tidy-up: use more static, sizeof(), char[], double-const

- make `const` data `static`, where missing and possible.
- replace `strlen()` on literal or const strings with `sizeof()`.
  While the latter is optimized by popular C compiler, e.g. MSVC only
  does it with `/O2`.
- replace magic numbers with `sizeof()`, where missing.
- introduce `CURL_CSTRLEN()` macro for `sizeof(char[]) - 1`.
- use `CURL_CSTRLEN()` macro.
- move `const` before integer types, where missing.
- replace `char *var` with `var[]`, where missing and possible.
- use double const, where missing.
  `static const char *` -> `static const char * const`.
- lib1514: constify pointers.
- unit3205: drop redundant cast, avoid another one.
- unit1666: map `OID()` macro to identical `STRCONST()`.

Closes #22406
This commit is contained in:
Viktor Szakats 2026-07-23 01:50:06 +02:00
parent 573a6ec16b
commit e1450d8fda
No known key found for this signature in database
117 changed files with 311 additions and 287 deletions

View file

@ -65,7 +65,7 @@ int main(void)
#include <netdb.h>
int main(void)
{
const char *address = "localhost";
static const char address[] = "localhost";
struct hostent h;
int rc = 0;
#if defined(HAVE_GETHOSTBYNAME_R_3) || \

View file

@ -30,7 +30,7 @@
#include <curl/curl.h>
static const char *urls[] = {
static const char * const urls[] = {
"https://01.example/",
"https://02.example/",
"https://03.example/",

View file

@ -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)

View file

@ -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;

View file

@ -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);

View file

@ -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)) {

View file

@ -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;

View file

@ -40,7 +40,7 @@
#define TO "<addressee@example.net>"
#define CC "<info@example.org>"
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);

View file

@ -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/",

View file

@ -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);

View file

@ -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)

View file

@ -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 */

View file

@ -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());

View file

@ -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);

View file

@ -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;

View file

@ -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"

View file

@ -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"

View file

@ -41,7 +41,7 @@
#define TO "<addressee@example.net>"
#define CC "<info@example.org>"
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");

View file

@ -38,7 +38,7 @@
#define TO_MAIL "<recipient@example.com>"
#define CC_MAIL "<info@example.com>"
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"

View file

@ -42,7 +42,7 @@
#define TO_MAIL "<recipient@example.com>"
#define CC_MAIL "<info@example.com>"
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"

View file

@ -42,7 +42,7 @@
#define TO_MAIL "<recipient@example.com>"
#define CC_MAIL "<info@example.com>"
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"

View file

@ -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"
};

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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]))

View file

@ -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) {

View file

@ -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,

View file

@ -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];

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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));

View file

@ -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;

View file

@ -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;

View file

@ -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",

View file

@ -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;

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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)

View file

@ -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"

View file

@ -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;

View file

@ -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

View file

@ -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) {

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -29,7 +29,7 @@
* function in url.c.
*/
static const char *scheme[] = {
static const char * const scheme[] = {
"dict",
"file",
"ftp",

View file

@ -43,7 +43,7 @@
#include <openssl/opensslconf.h> /* for OPENSSL_NO_OCSP */
#endif
static const char *disabled[] = {
static const char * const disabled[] = {
"bindlocal: "
#ifdef CURL_DISABLE_BINDLOCAL
"OFF"

View file

@ -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;

View file

@ -64,7 +64,7 @@ static const char * const srchard[] = {
"",
NULL
};
static const char *const srcend[] = {
static const char * const srcend[] = {
"",
" return (int)result;",
"}",

View file

@ -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);

View file

@ -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",

View file

@ -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",

View file

@ -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;

View file

@ -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,

View file

@ -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);

View file

@ -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 */

View file

@ -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;

View file

@ -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);

View file

@ -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");

View file

@ -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",

View file

@ -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)
{

View file

@ -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)
{

View file

@ -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)
{

View file

@ -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;

View file

@ -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;

View file

@ -23,7 +23,7 @@
***************************************************************************/
#include "first.h"
static const char *ldata_names[] = {
static const char * const ldata_names[] = {
"NONE",
"SHARE",
"COOKIE",

View file

@ -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]"

View file

@ -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)
{

View file

@ -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 */

View file

@ -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);

View file

@ -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;

View file

@ -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]) {

View file

@ -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",

View file

@ -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:

View file

@ -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--",

View file

@ -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);
}
}

View file

@ -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: <url> <file-to-upload>\n");

View file

@ -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");

View file

@ -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) {

View file

@ -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;

View file

@ -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)
{

View file

@ -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,

View file

@ -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)
{

View file

@ -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;

View file

@ -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);

View file

@ -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. */

View file

@ -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,

View file

@ -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);

View file

@ -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. */

View file

@ -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;
}

View file

@ -24,7 +24,7 @@
#include "first.h"
static const char t757_data[] = "<title>fun-times</title>";
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)
{

View file

@ -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);
}

View file

@ -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 =
"</BODY></HTML>\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 */

View file

@ -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)

Some files were not shown because too many files have changed in this diff Show more