← Commit list

e1450d8fda

Viktor Szakats
Viktor Szakats
2026-07-28
SUCCESS Duration: 191s

Subject

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

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

CMake/CurlTests.c +1 -1docs/examples/10-at-a-time.c +1 -1docs/examples/crawler.c +1 -1docs/examples/ephiperfifo.c +4 -2docs/examples/evhiperfifo.c +4 -2docs/examples/ghiper.c +4 -2docs/examples/hiperfifo.c +4 -2docs/examples/imap-append.c +2 -2docs/examples/maxconnects.c +1 -1docs/examples/postinmemory.c +2 -2docs/examples/sendrecv.c +2 -2docs/examples/sepheaders.c +2 -2docs/examples/sftpuploadresume.c +2 -2docs/examples/simplepost.c +2 -2docs/examples/simplessl.c +3 -3docs/examples/smtp-authzid.c +1 -1docs/examples/smtp-mail.c +1 -1docs/examples/smtp-mime.c +2 -2docs/examples/smtp-multi.c +1 -1docs/examples/smtp-ssl.c +1 -1docs/examples/smtp-tls.c +1 -1docs/examples/synctime.c +2 -2docs/examples/url2file.c +1 -1docs/examples/websocket-updown.c +2 -2lib/cf-h1-proxy.c +2 -2lib/cf-h2-proxy.c +1 -1lib/curl_setup.h +5 -1lib/dict.c +6 -6lib/http.c +1 -1lib/http2.c +2 -2lib/http_aws_sigv4.c +2 -2lib/http_digest.c +1 -1lib/http_negotiate.c +1 -1lib/http_ntlm.c +1 -1lib/http_proxy.c +3 -3lib/imap.c +1 -1lib/ldap.c +2 -2lib/mqtt.c +2 -2lib/progress.c +1 -1lib/smb.c +5 -4lib/tftp.c +2 -2lib/vquic/cf-quiche.c +3 -4lib/vssh/libssh2.c +1 -1lib/vtls/cipher_suite.c +1 -1lib/vtls/gtls.c +3 -3lib/vtls/keylog.h +1 -1lib/vtls/openssl.c +12 -12lib/vtls/schannel.c +6 -6lib/vtls/schannel_verify.c +2 -2lib/vtls/vtls.c +2 -2lib/vtls/wolfssl.c +4 -4scripts/schemetable.c +1 -1src/curlinfo.c +1 -1src/tool_doswin.c +3 -3src/tool_easysrc.c +1 -1src/tool_formparse.c +4 -4src/tool_getparam.c +1 -1src/tool_helpers.c +2 -2src/tool_libinfo.c +1 -1src/tool_paramhlp.c +1 -1src/tool_progress.c +1 -1src/var.c +5 -5tests/http/testenv/mod_curltest/mod_curltest.c +1 -1tests/libtest/lib1514.c +3 -3tests/libtest/lib1517.c +1 -1tests/libtest/lib1520.c +1 -1tests/libtest/lib1525.c +1 -1tests/libtest/lib1526.c +1 -1tests/libtest/lib1527.c +1 -1tests/libtest/lib1531.c +2 -2tests/libtest/lib1537.c +4 -2tests/libtest/lib1554.c +1 -1tests/libtest/lib1560.c +2 -2tests/libtest/lib1576.c +3 -2tests/libtest/lib1591.c +1 -1tests/libtest/lib1598.c +2 -2tests/libtest/lib1662.c +1 -1tests/libtest/lib1901.c +1 -1tests/libtest/lib1940.c +1 -1tests/libtest/lib1948.c +3 -3tests/libtest/lib1965.c +1 -1tests/libtest/lib3102.c +4 -4tests/libtest/lib505.c +2 -2tests/libtest/lib508.c +1 -1tests/libtest/lib536.c +1 -1tests/libtest/lib544.c +1 -1tests/libtest/lib547.c +1 -1tests/libtest/lib554.c +2 -2tests/libtest/lib555.c +1 -1tests/libtest/lib571.c +1 -1tests/libtest/lib643.c +2 -2tests/libtest/lib654.c +1 -1tests/libtest/lib655.c +1 -1tests/libtest/lib667.c +1 -1tests/libtest/lib668.c +1 -1tests/libtest/lib677.c +3 -3tests/libtest/lib757.c +1 -1tests/server/mqttd.c +4 -4tests/server/rtspd.c +20 -18tests/server/socksd.c +2 -2tests/server/sws.c +21 -19tests/tunit/tool1720.c +1 -1tests/unit/unit1303.c +1 -1tests/unit/unit1395.c +1 -1tests/unit/unit1396.c +2 -2tests/unit/unit1398.c +1 -1tests/unit/unit1625.c +2 -2tests/unit/unit1627.c +2 -2tests/unit/unit1650.c +7 -5tests/unit/unit1655.c +3 -3tests/unit/unit1664.c +12 -12tests/unit/unit1666.c +1 -1tests/unit/unit1675.c +6 -6tests/unit/unit2603.c +7 -7tests/unit/unit3200.c +1 -1tests/unit/unit3205.c +4 -3tests/unit/unit3400.c +17 -15
CMake/CurlTests.c+1 -1
@@ -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) || \
docs/examples/10-at-a-time.c+1 -1
@@ -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/",
docs/examples/crawler.c+1 -1
@@ -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)
docs/examples/ephiperfifo.c+4 -2
@@ -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;
docs/examples/evhiperfifo.c+4 -2
@@ -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);
docs/examples/ghiper.c+4 -2
@@ -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)) {
docs/examples/hiperfifo.c+4 -2
@@ -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;
docs/examples/imap-append.c+2 -2
@@ -40,7 +40,7 @@
#define TO "<[email protected]>"
#define CC "<[email protected]>"
-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);
docs/examples/maxconnects.c+1 -1
@@ -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/",
docs/examples/postinmemory.c+2 -2
@@ -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);
docs/examples/sendrecv.c+2 -2
@@ -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)
docs/examples/sepheaders.c+2 -2
@@ -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 */
docs/examples/sftpuploadresume.c+2 -2
@@ -134,8 +134,8 @@ int main(void)
curl = curl_easy_init();
if(curl) {
- const char *remote = "sftp://user:[email protected]/path/filename";
- const char *filename = "filename";
+ static const char remote[] = "sftp://user:[email protected]/path/filename";
+ static const char filename[] = "filename";
if(!sftpResumeUpload(curl, remote, filename)) {
printf("resumed upload using curl %s failed\n", curl_version());
docs/examples/simplepost.c+2 -2
@@ -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);
docs/examples/simplessl.c+3 -3
@@ -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;
docs/examples/smtp-authzid.c+1 -1
@@ -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"
docs/examples/smtp-mail.c+1 -1
@@ -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"
docs/examples/smtp-mime.c+2 -2
@@ -41,7 +41,7 @@
#define TO "<[email protected]>"
#define CC "<[email protected]>"
-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");
docs/examples/smtp-multi.c+1 -1
@@ -38,7 +38,7 @@
#define TO_MAIL "<[email protected]>"
#define CC_MAIL "<[email protected]>"
-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"
docs/examples/smtp-ssl.c+1 -1
@@ -42,7 +42,7 @@
#define TO_MAIL "<[email protected]>"
#define CC_MAIL "<[email protected]>"
-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"
docs/examples/smtp-tls.c+1 -1
@@ -42,7 +42,7 @@
#define TO_MAIL "<[email protected]>"
#define CC_MAIL "<[email protected]>"
-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"
docs/examples/synctime.c+2 -2
@@ -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"
};
docs/examples/url2file.c+1 -1
@@ -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;
docs/examples/websocket-updown.c+2 -2
@@ -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);
lib/cf-h1-proxy.c+2 -2
@@ -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;
lib/cf-h2-proxy.c+1 -1
@@ -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;
lib/curl_setup.h+5 -1
@@ -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]))
lib/dict.c+6 -6
@@ -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) {
lib/http.c+1 -1
@@ -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,
lib/http2.c+2 -2
@@ -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];
lib/http_aws_sigv4.c+2 -2
@@ -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);
lib/http_digest.c+1 -1
@@ -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);
lib/http_negotiate.c+1 -1
@@ -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);
lib/http_ntlm.c+1 -1
@@ -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;
lib/http_proxy.c+3 -3
@@ -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));
lib/imap.c+1 -1
@@ -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;
lib/ldap.c+2 -2
@@ -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;
lib/mqtt.c+2 -2
@@ -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",
lib/progress.c+1 -1
@@ -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;
lib/smb.c+5 -4
@@ -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;
lib/tftp.c+2 -2
@@ -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
lib/vquic/cf-quiche.c+3 -4
@@ -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;
lib/vssh/libssh2.c+1 -1
@@ -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)
lib/vtls/cipher_suite.c+1 -1
@@ -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"
lib/vtls/gtls.c+3 -3
@@ -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;
lib/vtls/keylog.h+1 -1
@@ -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
lib/vtls/openssl.c+12 -12
@@ -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) {
lib/vtls/schannel.c+6 -6
@@ -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);
lib/vtls/schannel_verify.c+2 -2
@@ -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;
lib/vtls/vtls.c+2 -2
@@ -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);
lib/vtls/wolfssl.c+4 -4
@@ -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;
scripts/schemetable.c+1 -1
@@ -29,7 +29,7 @@
* function in url.c.
*/
-static const char *scheme[] = {
+static const char * const scheme[] = {
"dict",
"file",
"ftp",
src/curlinfo.c+1 -1
@@ -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"
src/tool_doswin.c+3 -3
@@ -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;
src/tool_easysrc.c+1 -1
@@ -64,7 +64,7 @@ static const char * const srchard[] = {
"",
NULL
};
-static const char *const srcend[] = {
+static const char * const srcend[] = {
"",
" return (int)result;",
"}",
src/tool_formparse.c+4 -4
@@ -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);
src/tool_getparam.c+1 -1
@@ -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",
src/tool_helpers.c+2 -2
@@ -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",
src/tool_libinfo.c+1 -1
@@ -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;
src/tool_paramhlp.c+1 -1
@@ -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,
src/tool_progress.c+1 -1
@@ -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);
src/var.c+5 -5
@@ -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 */
tests/http/testenv/mod_curltest/mod_curltest.c+1 -1
@@ -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;
tests/libtest/lib1514.c+3 -3
@@ -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);
tests/libtest/lib1517.c+1 -1
@@ -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");
tests/libtest/lib1520.c+1 -1
@@ -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",
tests/libtest/lib1525.c+1 -1
@@ -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)
{
tests/libtest/lib1526.c+1 -1
@@ -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)
{
tests/libtest/lib1527.c+1 -1
@@ -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)
{
tests/libtest/lib1531.c+2 -2
@@ -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;
tests/libtest/lib1537.c+4 -2
@@ -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;
tests/libtest/lib1554.c+1 -1
@@ -23,7 +23,7 @@
***************************************************************************/
#include "first.h"
-static const char *ldata_names[] = {
+static const char * const ldata_names[] = {
"NONE",
"SHARE",
"COOKIE",
tests/libtest/lib1560.c+2 -2
@@ -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]"
tests/libtest/lib1576.c+3 -2
@@ -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)
{
tests/libtest/lib1591.c+1 -1
@@ -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 */
tests/libtest/lib1598.c+2 -2
@@ -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);
tests/libtest/lib1662.c+1 -1
@@ -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;
tests/libtest/lib1901.c+1 -1
@@ -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]) {
tests/libtest/lib1940.c+1 -1
@@ -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",
tests/libtest/lib1948.c+3 -3
@@ -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:
tests/libtest/lib1965.c+1 -1
@@ -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--",
tests/libtest/lib3102.c+4 -4
@@ -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);
}
}
tests/libtest/lib505.c+2 -2
@@ -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");
tests/libtest/lib508.c+1 -1
@@ -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");
tests/libtest/lib536.c+1 -1
@@ -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) {
tests/libtest/lib544.c+1 -1
@@ -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;
tests/libtest/lib547.c+1 -1
@@ -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)
{
tests/libtest/lib554.c+2 -2
@@ -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,
tests/libtest/lib555.c+1 -1
@@ -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)
{
tests/libtest/lib571.c+1 -1
@@ -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;
tests/libtest/lib643.c+2 -2
@@ -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);
tests/libtest/lib654.c+1 -1
@@ -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. */
tests/libtest/lib655.c+1 -1
@@ -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,
tests/libtest/lib667.c+1 -1
@@ -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);
tests/libtest/lib668.c+1 -1
@@ -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. */
tests/libtest/lib677.c+3 -3
@@ -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;
}
tests/libtest/lib757.c+1 -1
@@ -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)
{
tests/server/mqttd.c+4 -4
@@ -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);
}
tests/server/rtspd.c+20 -18
@@ -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 */
tests/server/socksd.c+2 -2
@@ -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)
tests/server/sws.c+21 -19
@@ -141,10 +141,10 @@ static const char *cmdfile = "log/server.cmd";
static const char *end_of_headers = END_OF_HEADERS;
/* sent as reply to a QUIT */
-static const char *docquit_sws = "HTTP/1.1 200 Goodbye" END_OF_HEADERS;
+static const char docquit_sws[] = "HTTP/1.1 200 Goodbye" END_OF_HEADERS;
/* send back this on 404 file not found */
-static const char *doc404 =
+static const char doc404[] =
"HTTP/1.1 404 Not Found\r\n"
"Server: " SWSVERSION "\r\n"
"Connection: close\r\n"
@@ -262,29 +262,29 @@ static int sws_parse_servercmd(struct sws_httprequest *req)
while(cmd && cmdsize) {
const char *check;
- if(!strncmp(CMD_AUTH_REQUIRED, cmd, strlen(CMD_AUTH_REQUIRED))) {
+ if(!strncmp(CMD_AUTH_REQUIRED, cmd, CURL_CSTRLEN(CMD_AUTH_REQUIRED))) {
logmsg("instructed to require authorization header");
req->auth_req = TRUE;
}
- else if(!strncmp(CMD_IDLE, cmd, strlen(CMD_IDLE))) {
+ else if(!strncmp(CMD_IDLE, cmd, CURL_CSTRLEN(CMD_IDLE))) {
logmsg("instructed to idle");
req->rcmd = RCMD_IDLE;
req->open = TRUE;
}
- else if(!strncmp(CMD_STREAM, cmd, strlen(CMD_STREAM))) {
+ else if(!strncmp(CMD_STREAM, cmd, CURL_CSTRLEN(CMD_STREAM))) {
logmsg("instructed to stream");
req->rcmd = RCMD_STREAM;
}
else if(!strncmp(CMD_CONNECTIONMONITOR, cmd,
- strlen(CMD_CONNECTIONMONITOR))) {
+ CURL_CSTRLEN(CMD_CONNECTIONMONITOR))) {
logmsg("enabled connection monitoring");
req->connmon = TRUE;
}
- else if(!strncmp(CMD_UPGRADE, cmd, strlen(CMD_UPGRADE))) {
+ else if(!strncmp(CMD_UPGRADE, cmd, CURL_CSTRLEN(CMD_UPGRADE))) {
logmsg("enabled upgrade");
req->upgrade = TRUE;
}
- else if(!strncmp(CMD_SWSCLOSE, cmd, strlen(CMD_SWSCLOSE))) {
+ else if(!strncmp(CMD_SWSCLOSE, cmd, CURL_CSTRLEN(CMD_SWSCLOSE))) {
logmsg("swsclose: close this connection after response");
req->close = TRUE;
}
@@ -292,7 +292,7 @@ static int sws_parse_servercmd(struct sws_httprequest *req)
logmsg("instructed to skip this number of bytes %d", num);
req->skip = num;
}
- else if(!strncmp(CMD_NOEXPECT, cmd, strlen(CMD_NOEXPECT))) {
+ else if(!strncmp(CMD_NOEXPECT, cmd, CURL_CSTRLEN(CMD_NOEXPECT))) {
logmsg("instructed to reject Expect: 100-continue");
req->noexpect = TRUE;
}
@@ -591,7 +591,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
ignore the content-length, we return as soon as all headers
have been received */
curl_off_t clen;
- const char *p = line + strlen("Content-Length:");
+ const char *p = line + CURL_CSTRLEN("Content-Length:");
if(curlx_str_numblanks(&p, &clen)) {
/* this assumes that a zero Content-Length is valid */
logmsg("Found invalid '%s' in the request", line);
@@ -608,12 +608,13 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
logmsg("... but going to abort after %zu bytes", req->cl);
}
else if(!CURL_STRNICMP("Transfer-Encoding: chunked", line,
- strlen("Transfer-Encoding: chunked"))) {
+ CURL_CSTRLEN("Transfer-Encoding: chunked"))) {
/* chunked data coming in */
chunked = TRUE;
}
- else if(req->noexpect && !CURL_STRNICMP("Expect: 100-continue", line,
- strlen("Expect: 100-continue"))) {
+ else if(req->noexpect &&
+ !CURL_STRNICMP("Expect: 100-continue", line,
+ CURL_CSTRLEN("Expect: 100-continue"))) {
if(req->cl)
req->cl = 0;
req->skipall = TRUE;
@@ -709,8 +710,8 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
req->prot_version >= 11 &&
req->reqbuf + req->offset > end + strlen(end_of_headers) &&
!req->cl &&
- (!strncmp(req->reqbuf, "GET", strlen("GET")) ||
- !strncmp(req->reqbuf, "HEAD", strlen("HEAD")))) {
+ (!strncmp(req->reqbuf, "GET", CURL_CSTRLEN("GET")) ||
+ !strncmp(req->reqbuf, "HEAD", CURL_CSTRLEN("HEAD")))) {
/* If we have a persistent connection, HTTP version >= 1.1
and GET/HEAD request, enable pipelining. */
req->checkindex = (end - req->reqbuf) + strlen(end_of_headers);
@@ -771,10 +772,10 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req)
case RCMD_STREAM: {
static const char streamthis[] = "a string to stream 01234567890\n";
for(;;) {
- written = swrite(sock, streamthis, sizeof(streamthis) - 1);
+ written = swrite(sock, streamthis, CURL_CSTRLEN(streamthis));
if(got_exit_signal)
return -1;
- if(written != (ssize_t)(sizeof(streamthis) - 1)) {
+ if(written != (ssize_t)CURL_CSTRLEN(streamthis)) {
logmsg("Stopped streaming");
break;
}
@@ -2325,8 +2326,9 @@ static int test_sws(int argc, const char *argv[])
logmsg("====> Client disconnect %d", req->connmon);
if(req->connmon) {
- const char *keepopen = "[DISCONNECT]\n";
- storerequest(keepopen, strlen(keepopen), REQUEST_DUMP_FILENAME);
+ static const char keepopen[] = "[DISCONNECT]\n";
+ storerequest(keepopen, CURL_CSTRLEN(keepopen),
+ REQUEST_DUMP_FILENAME);
}
if(!req->open)
tests/tunit/tool1720.c+1 -1
@@ -28,7 +28,7 @@ static CURLcode test_tool1720(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
- static const char *check[] = {
+ static const char * const check[] = {
"",
"(null)",
"filename",
tests/unit/unit1303.c+1 -1
@@ -85,7 +85,7 @@ static CURLcode test_unit1303(const char *arg)
const char *comment;
};
- const struct timetest run[] = {
+ static const struct timetest run[] = {
/* both timeouts set, not connecting */
{BASE + 4, 0, 10000, 8000, FALSE, 6000, "6 seconds should be left"},
{BASE + 4, 990000, 10000, 8000, FALSE, 5010, "5010 ms should be left"},
tests/unit/unit1395.c+1 -1
@@ -35,7 +35,7 @@ static CURLcode test_unit1395(const char *arg)
const char *output;
};
- const struct dotdot pairs[] = {
+ static const struct dotdot pairs[] = {
{ "/%2f%2e%2e%2f/../a", "/a" },
{ "/%2f%2e%2e%2f/../", "/" },
{ "/%2f%2e%2e%2f/.", "/%2f%2e%2e%2f/" },
tests/unit/unit1396.c+2 -2
@@ -51,7 +51,7 @@ static CURLcode test_unit1396(const char *arg)
};
/* unescape, this => that */
- const struct test list1[] = {
+ static const struct test list1[] = {
{ "%61", 3, "a", 1 },
{ "%61a", 4, "aa", 2 },
{ "%61b", 4, "ab", 2 },
@@ -67,7 +67,7 @@ static CURLcode test_unit1396(const char *arg)
{ NULL, 0, NULL, 0 } /* end of list marker */
};
/* escape, this => that */
- const struct test list2[] = {
+ static const struct test list2[] = {
{ "a", 1, "a", 1 },
{ "/", 1, "%2F", 3 },
{ "a=b", 3, "a%3Db", 5 },
tests/unit/unit1398.c+1 -1
@@ -34,7 +34,7 @@ static CURLcode test_unit1398(const char *arg)
int rc;
char buf[3] = { 'b', 'u', 'g' };
- static const char *str = "bug";
+ static const char str[] = "bug";
int width = 3;
char output[130];
tests/unit/unit1625.c+2 -2
@@ -41,8 +41,8 @@ static CURLcode test_unit1625(const char *arg)
char *large;
size_t i;
const size_t large_value_len = MAX_HTTP_RESP_HEADER_SIZE;
- const size_t large_prefix_len = strlen("Encoding: ");
- const size_t large_suffix_len = strlen(", chunked");
+ const size_t large_prefix_len = CURL_CSTRLEN("Encoding: ");
+ const size_t large_suffix_len = CURL_CSTRLEN(", chunked");
static const struct check1625 list[] = {
/* basic case */
{ "Encoding: gzip, chunked", "Encoding:", "chunked", TRUE },
tests/unit/unit1627.c+2 -2
@@ -32,7 +32,7 @@ static CURLcode test_unit1627(const char *arg)
size_t i, j;
/* existing schemes in different cases */
- static const char *okay[] = {
+ static const char * const okay[] = {
/* all upper */
"DICT", "FILE", "FTP", "FTPS", "GOPHER", "GOPHERS", "HTTP", "HTTPS",
"IMAP", "IMAPS", "LDAP", "LDAPS", "MQTT", "MQTTS", "POP3", "POP3S",
@@ -50,7 +50,7 @@ static CURLcode test_unit1627(const char *arg)
"TELNEt", "tFTP", "Ws", "wSS",
};
/* non-existing schemes */
- static const char *notokay[] = {
+ static const char * const notokay[] = {
"a", "A", "htt", "ttp", "httt", "http+", "HTTPP", "HTTPPS", "HTTSP",
"GROPHER", "D1CT", "AbG", "zLQp", "mNrtW", "PkY", "bVcxZq", "LmO",
"iUhyT", "rEwQA", "xSdfG", "nBvC", "pOiuY", "tRewQ", "aSdfG", "hJkl",
tests/unit/unit1650.c+7 -5
@@ -54,8 +54,10 @@ static CURLcode test_unit1650(const char *arg)
};
static const struct dohrequest req[] = {
- {"test.host.name", CURL_DNS_TYPE_A, DNS_Q1, sizeof(DNS_Q1)-1, DOH_OK },
- {"test.host.name", CURL_DNS_TYPE_AAAA, DNS_Q2, sizeof(DNS_Q2)-1, DOH_OK },
+ {"test.host.name",
+ CURL_DNS_TYPE_A, DNS_Q1, CURL_CSTRLEN(DNS_Q1), DOH_OK },
+ {"test.host.name",
+ CURL_DNS_TYPE_AAAA, DNS_Q2, CURL_CSTRLEN(DNS_Q2), DOH_OK },
{"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
".host.name",
CURL_DNS_TYPE_AAAA, NULL, 0, DOH_DNS_BAD_LABEL }
@@ -235,7 +237,7 @@ static CURLcode test_unit1650(const char *arg)
}
/* pass all sizes into the decoder until full */
- for(i = 0; i < sizeof(full49) - 1; i++) {
+ for(i = 0; i < CURL_CSTRLEN(full49); i++) {
struct dohentry d;
DOHcode rc;
memset(&d, 0, sizeof(d));
@@ -267,8 +269,8 @@ static CURLcode test_unit1650(const char *arg)
struct dohentry d;
struct dohaddr *a;
memset(&d, 0, sizeof(d));
- rc = doh_resp_decode((const unsigned char *)full49,
- sizeof(full49) - 1, CURL_DNS_TYPE_A, &d);
+ rc = doh_resp_decode((const unsigned char *)full49, CURL_CSTRLEN(full49),
+ CURL_DNS_TYPE_A, &d);
fail_if(d.numaddr != 1, "missing address");
a = &d.addr[0];
p = &a->ip.v4[0];
tests/unit/unit1655.c+3 -3
@@ -132,9 +132,9 @@ static CURLcode test_unit1655(const char *arg)
const size_t buflen = sizeof(buffer);
const size_t magic1 = 9765;
size_t olen1 = magic1;
- static const char *sunshine1 = "a.com";
- static const char *dotshine1 = "a.com.";
- static const char *sunshine2 = "aa.com";
+ static const char sunshine1[] = "a.com";
+ static const char dotshine1[] = "a.com.";
+ static const char sunshine2[] = "aa.com";
size_t olen2;
DOHcode ret2;
size_t olen;
tests/unit/unit1664.c+12 -12
@@ -41,7 +41,7 @@ static CURLcode test_unit1664(const char *arg)
{
UNITTEST_BEGIN(t1664_setup())
- static const char *wordparse[] = {
+ static const char * const wordparse[] = {
"word",
"word ",
" word ",
@@ -78,7 +78,7 @@ static CURLcode test_unit1664(const char *arg)
}
{
- static const char *qwords[] = {
+ static const char * const qwords[] = {
"\"word\"",
"\"word",
"word\"",
@@ -112,7 +112,7 @@ static CURLcode test_unit1664(const char *arg)
}
{
- static const char *single[] = {
+ static const char * const single[] = {
"a",
"aa",
"A",
@@ -133,7 +133,7 @@ static CURLcode test_unit1664(const char *arg)
}
{
- static const char *single[] = {
+ static const char * const single[] = {
"a",
"aa",
"A",
@@ -156,7 +156,7 @@ static CURLcode test_unit1664(const char *arg)
}
{
- static const char *single[] = {
+ static const char * const single[] = {
"a",
"aa",
"A",
@@ -177,7 +177,7 @@ static CURLcode test_unit1664(const char *arg)
}
{
- static const char *nums[] = {
+ static const char * const nums[] = {
"1",
"10000",
"1234",
@@ -313,7 +313,7 @@ static CURLcode test_unit1664(const char *arg)
{
/* CURL_OFF_T is typically 9223372036854775807 */
- static const char *nums[] = {
+ static const char * const nums[] = {
"9223372036854775807", /* 2^63 -1 */
"9223372036854775808", /* 2^63 */
"18446744073709551615", /* 2^64 - 1 */
@@ -347,7 +347,7 @@ static CURLcode test_unit1664(const char *arg)
}
{
- static const char *newl[] = {
+ static const char * const newl[] = {
"a",
"aa",
"A",
@@ -372,7 +372,7 @@ static CURLcode test_unit1664(const char *arg)
}
{
- static const char *nums[] = {
+ static const char * const nums[] = {
"1",
"1000",
"1234",
@@ -399,7 +399,7 @@ static CURLcode test_unit1664(const char *arg)
}
{
- static const char *nums[] = {
+ static const char * const nums[] = {
"1",
"1000",
"1234",
@@ -427,7 +427,7 @@ static CURLcode test_unit1664(const char *arg)
{
/* CURL_OFF_T is typically 2^63-1 */
- static const char *nums[] = {
+ static const char * const nums[] = {
"777777777777777777777", /* 2^63 -1 */
"1000000000000000000000", /* 2^63 */
"111111111111111111111",
@@ -451,7 +451,7 @@ static CURLcode test_unit1664(const char *arg)
{
/* CURL_OFF_T is typically 2^63-1 */
- static const char *nums[] = {
+ static const char * const nums[] = {
"7FFFFFFFFFFFFFFF", /* 2^63 -1 */
"8000000000000000", /* 2^63 */
"1111111111111111",
tests/unit/unit1666.c+1 -1
@@ -36,7 +36,7 @@ struct test_1666 {
};
/* the size of the object needs to deduct the null-terminator */
-#define OID(x) x, sizeof(x) - 1
+#define OID(x) STRCONST(x)
static bool test1666(const struct test_1666 *spec, size_t i,
struct dynbuf *dbuf)
tests/unit/unit1675.c+6 -6
@@ -38,7 +38,7 @@ static CURLcode test_unit1675(const char *arg)
const char *in;
const char *out;
};
- const struct ipv4_test tests[] = {
+ static const struct ipv4_test tests[] = {
{ "0x.0x.0x.0x", NULL }, /* invalid hex */
{ "0x.0x.0x", NULL }, /* invalid hex */
{ "0x.0x", NULL }, /* invalid hex */
@@ -146,7 +146,7 @@ static CURLcode test_unit1675(const char *arg)
unsigned int query;
const char *out;
};
- const struct urlencode_test tests[] = {
+ static const struct urlencode_test tests[] = {
{ "http://leave\x01/hello\x01world", FALSE, QUERY_NO,
"http://leave\x01/hello%01world" },
{ "http://leave/hello\x01world", FALSE, QUERY_NO,
@@ -204,7 +204,7 @@ static CURLcode test_unit1675(const char *arg)
const char *out_host;
const char *out_zone;
};
- const struct ipv6_test tests[] = {
+ static const struct ipv6_test tests[] = {
{ "[::1]", "[::1]", NULL },
{ "[fe80::1%eth0]", "[fe80::1]", "eth0" },
{ "[fe80::1%25eth0]", "[fe80::1]", "eth0" },
@@ -260,7 +260,7 @@ static CURLcode test_unit1675(const char *arg)
const char *out_path;
bool fine;
};
- const struct file_test tests[] = {
+ static const struct file_test tests[] = {
{ "file:///etc/hosts", "/etc/hosts", TRUE },
{ "file://localhost/etc/hosts", "/etc/hosts", TRUE },
{ "file://apple/etc/hosts", "/etc/hosts", FALSE },
@@ -317,7 +317,7 @@ static CURLcode test_unit1675(const char *arg)
const char *path;
bool expect_match;
};
- const struct origin_test tests[] = {
+ static const struct origin_test tests[] = {
{ "http://host:123/x", "http", "host", "123", "/y", TRUE },
{ "http://host:123/x", NULL, "host", "123", "/y", TRUE },
{ "http://host:123/x", NULL, NULL, NULL, "/y", TRUE },
@@ -395,7 +395,7 @@ loop_end:
const char *options;
size_t offset;
};
- const struct test tests[] = {
+ static const struct test tests[] = {
{ CURLUE_OK, "foo:bar@host", NULL, 0, "foo", "bar", "o", 8 },
{ CURLUE_OK, "foo:bar;abc@host", "imap", 0, "foo", "bar", "abc", 12 },
{ CURLUE_OK, "foo:bar;abc@host", NULL, 0, "foo", "bar;abc", "o", 12 },
tests/unit/unit2603.c+7 -7
@@ -48,7 +48,7 @@ static void check_eq(const char *s, const char *exp_s, const char *name)
}
struct tcase {
- const char **input;
+ const char * const *input;
const char *default_scheme;
const char *custom_method;
const char *method;
@@ -117,7 +117,7 @@ static CURLcode test_unit2603(const char *arg)
UNITTEST_BEGIN_SIMPLE
#ifndef CURL_DISABLE_HTTP
- static const char *T1_INPUT[] = {
+ static const char * const T1_INPUT[] = {
"GET /path HTTP/1.1\r\nHost: test.curl.se\r\n\r\n",
NULL,
};
@@ -128,7 +128,7 @@ static CURLcode test_unit2603(const char *arg)
T1_INPUT, "https", NULL, "GET", "https", NULL, "/path", 1, 0
};
- static const char *T2_INPUT[] = {
+ static const char * const T2_INPUT[] = {
"GET /path HTT",
"P/1.1\r\nHost: te",
"st.curl.se\r\n\r",
@@ -139,7 +139,7 @@ static CURLcode test_unit2603(const char *arg)
T2_INPUT, NULL, NULL, "GET", NULL, NULL, "/path", 1, 8
};
- static const char *T3_INPUT[] = {
+ static const char * const T3_INPUT[] = {
"GET ftp://ftp.curl.se/xxx?a=2 HTTP/1.1\r\nContent-Length: 0\r",
"\nUser-Agent: xxx\r\n\r\n",
NULL,
@@ -148,7 +148,7 @@ static CURLcode test_unit2603(const char *arg)
T3_INPUT, NULL, NULL, "GET", "ftp", "ftp.curl.se", "/xxx?a=2", 2, 0
};
- static const char *T4_INPUT[] = {
+ static const char * const T4_INPUT[] = {
"CONNECT ftp.curl.se:123 HTTP/1.1\r\nContent-Length: 0\r\n",
"User-Agent: xxx\r\n",
"nothing: \r\n\r\n\n\n",
@@ -158,7 +158,7 @@ static CURLcode test_unit2603(const char *arg)
T4_INPUT, NULL, NULL, "CONNECT", NULL, "ftp.curl.se:123", NULL, 3, 2
};
- static const char *T6_INPUT[] = {
+ static const char * const T6_INPUT[] = {
"PUT /path HTTP/1.1\nHost: test.curl.se\n\n123",
NULL,
};
@@ -167,7 +167,7 @@ static CURLcode test_unit2603(const char *arg)
};
/* test a custom method with space, #19543 */
- static const char *T7_INPUT[] = {
+ static const char * const T7_INPUT[] = {
"IN SANE /path HTTP/1.1\r\nContent-Length: 0\r\n\r\n",
NULL,
};
tests/unit/unit3200.c+1 -1
@@ -45,7 +45,7 @@ static CURLcode test_unit3200(const char *arg)
#define C1024 C256 C256 C256 C256
#define C4096 C1024 C1024 C1024 C1024
- static const char *filecontents[] = {
+ static const char * const filecontents[] = {
/* Both should be read */
"LINE1\n"
"LINE2 NEWLINE\n",
tests/unit/unit3205.c+4 -3
@@ -420,7 +420,7 @@ static CURLcode test_unit3205(const char *arg)
#endif
};
- static const char *cs_test_string =
+ static const char cs_test_string[] =
"TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:"
"TLS_CHACHA20_POLY1305_SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:"
"ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:"
@@ -561,11 +561,12 @@ static CURLcode test_unit3205(const char *arg)
if(test->id >= 0x0011 && test->id < 0x0017) {
if(expect && !memcmp(expect, "EDH-", 4)) {
curlx_strcopy(alt, sizeof(alt), expect, strlen(expect));
- expect = (const char *)memcpy(alt, "DHE-", sizeof("DHE-") - 1);
+ expect = memcpy(alt, "DHE-", CURL_CSTRLEN("DHE-"));
}
if(expect && !memcmp(expect + 4, "EDH-", 4)) {
curlx_strcopy(alt, sizeof(alt), expect, strlen(expect));
- expect = (const char *)memcpy(alt + 4, "DHE-", sizeof("DHE-") - 1) - 4;
+ expect = memcpy(alt + 4, "DHE-", CURL_CSTRLEN("DHE-"));
+ expect -= 4;
}
}
tests/unit/unit3400.c+17 -15
@@ -56,13 +56,13 @@ static void check_capsule_hdr(size_t payload_len,
static void test_capsule_encap_udp_hdr_boundaries(void)
{
- const unsigned char p0[] = { 0x00, 0x01, 0x00 };
- const unsigned char p62[] = { 0x00, 0x3F, 0x00 };
- const unsigned char p63[] = { 0x00, 0x40, 0x40, 0x00 };
- const unsigned char p64[] = { 0x00, 0x40, 0x41, 0x00 };
- const unsigned char p16382[] = { 0x00, 0x7F, 0xFF, 0x00 };
- const unsigned char p16383[] = { 0x00, 0x80, 0x00, 0x40, 0x00, 0x00 };
- const unsigned char p16384[] = { 0x00, 0x80, 0x00, 0x40, 0x01, 0x00 };
+ static const unsigned char p0[] = { 0x00, 0x01, 0x00 };
+ static const unsigned char p62[] = { 0x00, 0x3F, 0x00 };
+ static const unsigned char p63[] = { 0x00, 0x40, 0x40, 0x00 };
+ static const unsigned char p64[] = { 0x00, 0x40, 0x41, 0x00 };
+ static const unsigned char p16382[] = { 0x00, 0x7F, 0xFF, 0x00 };
+ static const unsigned char p16383[] = { 0x00, 0x80, 0x00, 0x40, 0x00, 0x00 };
+ static const unsigned char p16384[] = { 0x00, 0x80, 0x00, 0x40, 0x01, 0x00 };
check_capsule_hdr(0, p0, sizeof(p0));
check_capsule_hdr(62, p62, sizeof(p62));
@@ -139,7 +139,7 @@ static void test_capsule_sequential_decode(void)
CURLcode err;
size_t nread;
/* Two back-to-back 3-byte UDP capsules */
- const unsigned char two_caps[] = {
+ static const unsigned char two_caps[] = {
0x00, 0x04, 0x00, 0x11, 0x22, 0x33, /* capsule 1: [0x11,0x22,0x33] */
0x00, 0x04, 0x00, 0xAA, 0xBB, 0xCC /* capsule 2: [0xAA,0xBB,0xCC] */
};
@@ -186,13 +186,15 @@ static void test_capsule_decode_paths(void)
unsigned char out[8];
CURLcode err = CURLE_OK;
size_t nread;
- const unsigned char invalid_type[] = { 0x01 };
- const unsigned char partial_len[] = { 0x00, 0x40 };
- const unsigned char invalid_context[] = { 0x00, 0x01, 0x01 };
- const unsigned char invalid_caps_len[] = { 0x00, 0x00, 0x00 };
- const unsigned char partial_payload[] = { 0x00, 0x04, 0x00, 0x11, 0x22 };
- const unsigned char payload_3b[] = { 0x00, 0x04, 0x00, 0x11, 0x22, 0x33 };
- const unsigned char payload_empty[] = { 0x00, 0x01, 0x00 };
+ static const unsigned char invalid_type[] = { 0x01 };
+ static const unsigned char partial_len[] = { 0x00, 0x40 };
+ static const unsigned char invalid_context[] = { 0x00, 0x01, 0x01 };
+ static const unsigned char invalid_caps_len[] = { 0x00, 0x00, 0x00 };
+ static const unsigned char partial_payload[] = { 0x00, 0x04, 0x00, 0x11,
+ 0x22 };
+ static const unsigned char payload_3b[] = { 0x00, 0x04, 0x00,
+ 0x11, 0x22, 0x33 };
+ static const unsigned char payload_empty[] = { 0x00, 0x01, 0x00 };
Curl_bufq_init2(&q, 32, 4, BUFQ_OPT_NONE);