From: Denton Liu <liu.denton@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: "Jeff King" <peff@peff.net>,
"Chris Torek" <chris.torek@gmail.com>,
"Đoàn Trần Công Danh" <congdanhqx@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH v3 1/3] remote-curl: use strlen() instead of magic numbers
Date: Tue, 23 Jun 2020 13:55:32 -0400 [thread overview]
Message-ID: <cb8683837c9f583274780057621255a65a1c4c9f.1592934880.git.liu.denton@gmail.com> (raw)
In-Reply-To: <cover.1592934880.git.liu.denton@gmail.com>
When we are dealing with a packet-line length header, we use the magic
literal `4`, representing the length of "0000" and "0001", the packet
line length headers. Use `strlen("000x")` so that we do not have to use
the magic literal.
Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
remote-curl.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/remote-curl.c b/remote-curl.c
index 75532a8bae..a2cbef546b 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -596,10 +596,10 @@ static int rpc_read_from_out(struct rpc_state *rpc, int options,
set_packet_header(buf - 4, *appended);
break;
case PACKET_READ_DELIM:
- memcpy(buf - 4, "0001", 4);
+ memcpy(buf - strlen("0001"), "0001", strlen("0001"));
break;
case PACKET_READ_FLUSH:
- memcpy(buf - 4, "0000", 4);
+ memcpy(buf - strlen("0000"), "0000", strlen("0000"));
break;
case PACKET_READ_RESPONSE_END:
die(_("remote server sent stateless separator"));
@@ -804,7 +804,7 @@ static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, NULL);
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, "0000");
- curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, 4);
+ curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, strlen("0000"));
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buf);
--
2.27.0.307.g7979e895e7
next prev parent reply other threads:[~2020-06-23 17:55 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-13 13:43 [PATCH] pkt-line: extract out PACKET_HEADER_SIZE Denton Liu
2020-06-13 14:23 ` Đoàn Trần Công Danh
2020-06-13 14:39 ` Denton Liu
2020-06-13 16:51 ` Junio C Hamano
2020-06-14 18:24 ` Junio C Hamano
2020-06-14 7:31 ` Denton Liu
2020-06-14 7:31 ` [PATCH v2 0/3] pkt-line: war on magical `4` literal Denton Liu
2020-06-14 7:31 ` [PATCH v2 1/3] remote-curl: use strlen() instead of magic numbers Denton Liu
2020-06-14 7:31 ` [PATCH v2 2/3] pkt-line: use string versions of functions Denton Liu
2020-06-14 8:31 ` Đoàn Trần Công Danh
2020-06-14 9:07 ` [PATCH v2] " Denton Liu
2020-06-14 21:35 ` Junio C Hamano
2020-06-14 22:28 ` Denton Liu
2020-06-15 12:32 ` Đoàn Trần Công Danh
2020-06-14 7:32 ` [PATCH v2 3/3] pkt-line: extract out PACKET_HEADER_SIZE Denton Liu
2020-06-14 21:32 ` [PATCH v2 0/3] pkt-line: war on magical `4` literal Junio C Hamano
2020-06-23 17:55 ` [PATCH v3 " Denton Liu
2020-06-23 17:55 ` Denton Liu [this message]
2020-06-23 18:54 ` [PATCH v3 1/3] remote-curl: use strlen() instead of magic numbers Jeff King
2020-06-23 19:39 ` Junio C Hamano
2020-06-23 17:55 ` [PATCH v3 2/3] pkt-line: use string versions of functions Denton Liu
2020-06-23 19:11 ` Jeff King
2020-06-23 17:55 ` [PATCH v3 3/3] pkt-line: extract out PACKET_HEADER_SIZE Denton Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cb8683837c9f583274780057621255a65a1c4c9f.1592934880.git.liu.denton@gmail.com \
--to=liu.denton@gmail.com \
--cc=chris.torek@gmail.com \
--cc=congdanhqx@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).