summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHenrikHolst <henrik.holst@millistream.com>2022-02-07 19:25:09 +0100
committerDaniel Stenberg <daniel@haxx.se>2022-02-09 13:52:47 +0100
commitb8072192926b28239aee989ac551d4c8fa8e0cf8 (patch)
treed2a22f036dc80196c0849b6c32b245dce7286111 /lib
parent2a1951519e78c1aa404ec0201b9eaeae469d757b (diff)
downloadcurl-b8072192926b28239aee989ac551d4c8fa8e0cf8.tar.gz
misc: reduce strlen() calls with Curl_dyn_add()
Use STRCONST() to switch from Curl_dyn_add() to Curl_dyn_addn() for string literals. Closes #8398
Diffstat (limited to 'lib')
-rw-r--r--lib/c-hyper.c4
-rw-r--r--lib/doh.c2
-rw-r--r--lib/http.c34
-rw-r--r--lib/http2.c10
-rw-r--r--lib/http_chunks.c2
-rw-r--r--lib/http_proxy.c5
-rw-r--r--lib/rtsp.c14
7 files changed, 37 insertions, 34 deletions
diff --git a/lib/c-hyper.c b/lib/c-hyper.c
index c253cd36e..352ba9785 100644
--- a/lib/c-hyper.c
+++ b/lib/c-hyper.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -142,7 +142,7 @@ static int hyper_each_header(void *userdata,
return HYPER_ITER_BREAK;
}
else {
- if(Curl_dyn_add(&data->state.headerb, "\r\n"))
+ if(Curl_dyn_addn(&data->state.headerb, STRCONST("\r\n")))
return HYPER_ITER_BREAK;
}
len = Curl_dyn_len(&data->state.headerb);
diff --git a/lib/doh.c b/lib/doh.c
index 8e1fc9e23..292f5dc66 100644
--- a/lib/doh.c
+++ b/lib/doh.c
@@ -530,7 +530,7 @@ static DOHcode store_cname(const unsigned char *doh,
if(length) {
if(Curl_dyn_len(c)) {
- if(Curl_dyn_add(c, "."))
+ if(Curl_dyn_addn(c, STRCONST(".")))
return DOH_OUT_OF_MEM;
}
if((index + length) > dohlen)
diff --git a/lib/http.c b/lib/http.c
index 94cccf796..81bc846de 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -1540,7 +1540,7 @@ static CURLcode add_haproxy_protocol_header(struct Curl_easy *data)
#ifdef USE_UNIX_SOCKETS
if(data->conn->unix_domain_socket)
/* the buffer is large enough to hold this! */
- result = Curl_dyn_add(&req, "PROXY UNKNOWN\r\n");
+ result = Curl_dyn_addn(&req, STRCONST("PROXY UNKNOWN\r\n"));
else {
#endif
/* Emit the correct prefix for IPv6 */
@@ -1713,7 +1713,7 @@ static CURLcode expect100(struct Curl_easy *data,
Curl_compareheader(ptr, STRCONST("Expect:"), STRCONST("100-continue"));
}
else {
- result = Curl_dyn_add(req, "Expect: 100-continue\r\n");
+ result = Curl_dyn_addn(req, STRCONST("Expect: 100-continue\r\n"));
if(!result)
data->state.expect100header = TRUE;
}
@@ -2404,7 +2404,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
}
/* end of headers */
- result = Curl_dyn_add(r, "\r\n");
+ result = Curl_dyn_addn(r, STRCONST("\r\n"));
if(result)
return result;
@@ -2429,7 +2429,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
/* This is form posting using mime data. */
if(conn->bits.authneg) {
/* nothing to post! */
- result = Curl_dyn_add(r, "Content-Length: 0\r\n\r\n");
+ result = Curl_dyn_addn(r, STRCONST("Content-Length: 0\r\n\r\n"));
if(result)
return result;
@@ -2490,7 +2490,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
data->state.expect100header = FALSE;
/* make the request end in a true CRLF */
- result = Curl_dyn_add(r, "\r\n");
+ result = Curl_dyn_addn(r, STRCONST("\r\n"));
if(result)
return result;
@@ -2539,8 +2539,8 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
}
if(!Curl_checkheaders(data, "Content-Type")) {
- result = Curl_dyn_add(r, "Content-Type: application/"
- "x-www-form-urlencoded\r\n");
+ result = Curl_dyn_addn(r, STRCONST("Content-Type: application/"
+ "x-www-form-urlencoded\r\n"));
if(result)
return result;
}
@@ -2579,7 +2579,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
get the data duplicated with malloc() and family. */
/* end of headers! */
- result = Curl_dyn_add(r, "\r\n");
+ result = Curl_dyn_addn(r, STRCONST("\r\n"));
if(result)
return result;
@@ -2601,12 +2601,12 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
result = Curl_dyn_addn(r, data->set.postfields,
(size_t)http->postsize);
if(!result)
- result = Curl_dyn_add(r, "\r\n");
+ result = Curl_dyn_addn(r, STRCONST("\r\n"));
included_body += 2;
}
}
if(!result) {
- result = Curl_dyn_add(r, "\x30\x0d\x0a\x0d\x0a");
+ result = Curl_dyn_addn(r, STRCONST("\x30\x0d\x0a\x0d\x0a"));
/* 0 CR LF CR LF */
included_body += 5;
}
@@ -2629,7 +2629,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
Curl_pgrsSetUploadSize(data, http->postsize);
/* end of headers! */
- result = Curl_dyn_add(r, "\r\n");
+ result = Curl_dyn_addn(r, STRCONST("\r\n"));
if(result)
return result;
}
@@ -2638,14 +2638,14 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
#endif
{
/* end of headers! */
- result = Curl_dyn_add(r, "\r\n");
+ result = Curl_dyn_addn(r, STRCONST("\r\n"));
if(result)
return result;
if(data->req.upload_chunky && conn->bits.authneg) {
/* Chunky upload is selected and we're negotiating auth still, send
end-of-data only */
- result = Curl_dyn_add(r, (char *)"\x30\x0d\x0a\x0d\x0a");
+ result = Curl_dyn_addn(r, (char *)STRCONST("\x30\x0d\x0a\x0d\x0a"));
/* 0 CR LF CR LF */
if(result)
return result;
@@ -2673,7 +2673,7 @@ CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
break;
default:
- result = Curl_dyn_add(r, "\r\n");
+ result = Curl_dyn_addn(r, STRCONST("\r\n"));
if(result)
return result;
@@ -2723,7 +2723,7 @@ CURLcode Curl_http_cookies(struct Curl_easy *data,
while(co) {
if(co->value) {
if(0 == count) {
- result = Curl_dyn_add(r, "Cookie: ");
+ result = Curl_dyn_addn(r, STRCONST("Cookie: "));
if(result)
break;
}
@@ -2739,14 +2739,14 @@ CURLcode Curl_http_cookies(struct Curl_easy *data,
}
if(addcookies && !result) {
if(!count)
- result = Curl_dyn_add(r, "Cookie: ");
+ result = Curl_dyn_addn(r, STRCONST("Cookie: "));
if(!result) {
result = Curl_dyn_addf(r, "%s%s", count?"; ":"", addcookies);
count++;
}
}
if(count && !result)
- result = Curl_dyn_add(r, "\r\n");
+ result = Curl_dyn_addn(r, STRCONST("\r\n"));
if(result)
return result;
diff --git a/lib/http2.c b/lib/http2.c
index 26ab2aa81..b8c9773a0 100644
--- a/lib/http2.c
+++ b/lib/http2.c
@@ -758,7 +758,7 @@ static int on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame,
stream->status_code = -1;
}
- result = Curl_dyn_add(&stream->header_recvbuf, "\r\n");
+ result = Curl_dyn_addn(&stream->header_recvbuf, STRCONST("\r\n"));
if(result)
return NGHTTP2_ERR_CALLBACK_FAILURE;
@@ -1081,14 +1081,14 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame,
stream->status_code = decode_status_code(value, valuelen);
DEBUGASSERT(stream->status_code != -1);
- result = Curl_dyn_add(&stream->header_recvbuf, "HTTP/2 ");
+ result = Curl_dyn_addn(&stream->header_recvbuf, STRCONST("HTTP/2 "));
if(result)
return NGHTTP2_ERR_CALLBACK_FAILURE;
result = Curl_dyn_addn(&stream->header_recvbuf, value, valuelen);
if(result)
return NGHTTP2_ERR_CALLBACK_FAILURE;
/* the space character after the status code is mandatory */
- result = Curl_dyn_add(&stream->header_recvbuf, " \r\n");
+ result = Curl_dyn_addn(&stream->header_recvbuf, STRCONST(" \r\n"));
if(result)
return NGHTTP2_ERR_CALLBACK_FAILURE;
/* if we receive data for another handle, wake that up */
@@ -1106,13 +1106,13 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame,
result = Curl_dyn_addn(&stream->header_recvbuf, name, namelen);
if(result)
return NGHTTP2_ERR_CALLBACK_FAILURE;
- result = Curl_dyn_add(&stream->header_recvbuf, ": ");
+ result = Curl_dyn_addn(&stream->header_recvbuf, STRCONST(": "));
if(result)
return NGHTTP2_ERR_CALLBACK_FAILURE;
result = Curl_dyn_addn(&stream->header_recvbuf, value, valuelen);
if(result)
return NGHTTP2_ERR_CALLBACK_FAILURE;
- result = Curl_dyn_add(&stream->header_recvbuf, "\r\n");
+ result = Curl_dyn_addn(&stream->header_recvbuf, STRCONST("\r\n"));
if(result)
return NGHTTP2_ERR_CALLBACK_FAILURE;
/* if we receive data for another handle, wake that up */
diff --git a/lib/http_chunks.c b/lib/http_chunks.c
index 72d6f385b..7edfd6472 100644
--- a/lib/http_chunks.c
+++ b/lib/http_chunks.c
@@ -214,7 +214,7 @@ CHUNKcode Curl_httpchunk_read(struct Curl_easy *data,
if(tr) {
size_t trlen;
- result = Curl_dyn_add(&conn->trailer, (char *)"\x0d\x0a");
+ result = Curl_dyn_addn(&conn->trailer, (char *)STRCONST("\x0d\x0a"));
if(result)
return CHUNKE_OUT_OF_MEMORY;
diff --git a/lib/http_proxy.c b/lib/http_proxy.c
index 90f1bd9d9..3ffb026a1 100644
--- a/lib/http_proxy.c
+++ b/lib/http_proxy.c
@@ -329,14 +329,15 @@ static CURLcode CONNECT(struct Curl_easy *data,
data->set.str[STRING_USERAGENT]);
if(!result && !Curl_checkProxyheaders(data, conn, "Proxy-Connection"))
- result = Curl_dyn_add(req, "Proxy-Connection: Keep-Alive\r\n");
+ result = Curl_dyn_addn(req,
+ STRCONST("Proxy-Connection: Keep-Alive\r\n"));
if(!result)
result = Curl_add_custom_headers(data, TRUE, req);
if(!result)
/* CRLF terminate the request */
- result = Curl_dyn_add(req, "\r\n");
+ result = Curl_dyn_addn(req, STRCONST("\r\n"));
if(!result) {
/* Send the connect request to the proxy */
diff --git a/lib/rtsp.c b/lib/rtsp.c
index 30fefb9b8..cf1933abe 100644
--- a/lib/rtsp.c
+++ b/lib/rtsp.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -535,8 +535,9 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
if(rtspreq == RTSPREQ_SET_PARAMETER ||
rtspreq == RTSPREQ_GET_PARAMETER) {
if(!Curl_checkheaders(data, "Content-Type")) {
- result = Curl_dyn_addf(&req_buffer,
- "Content-Type: text/parameters\r\n");
+ result = Curl_dyn_addn(&req_buffer,
+ STRCONST("Content-Type: "
+ "text/parameters\r\n"));
if(result)
return result;
}
@@ -544,8 +545,9 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
if(rtspreq == RTSPREQ_ANNOUNCE) {
if(!Curl_checkheaders(data, "Content-Type")) {
- result = Curl_dyn_addf(&req_buffer,
- "Content-Type: application/sdp\r\n");
+ result = Curl_dyn_addn(&req_buffer,
+ STRCONST("Content-Type: "
+ "application/sdp\r\n"));
if(result)
return result;
}
@@ -563,7 +565,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done)
/* RTSP never allows chunked transfer */
data->req.forbidchunk = TRUE;
/* Finish the request buffer */
- result = Curl_dyn_add(&req_buffer, "\r\n");
+ result = Curl_dyn_addn(&req_buffer, STRCONST("\r\n"));
if(result)
return result;