git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 1/3] remote-curl: use strlen() instead of magic numbers

From
Denton Liu <liu.denton@gmail.com>
Date
Jun 23, 2020, 17:55 UTC
Message-ID
<cb8683837c9f583274780057621255a65a1c4c9f.1592934880.git.liu.denton@gmail.com>
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
Previous: Denton LiuNext: Jeff King
Message 17 of 22 in “pkt-line: extract out PACKET_HEADER_SIZE”
  1. pkt-line: extract out PACKET_HEADER_SIZEDenton Liu, Jun 13, 2020
  2. Đoàn Trần Công DanhJun 13, 2020
  3. Denton LiuJun 13, 2020
  4. Junio C HamanoJun 13, 2020
  5. Junio C HamanoJun 14, 2020
  6. 0/3 pkt-line: war on magical `4` literalDenton Liu, Jun 14, 2020
  7. 2/3 pkt-line: use string versions of functionsDenton Liu, Jun 14, 2020
  8. Đoàn Trần Công DanhJun 14, 2020
  9. pkt-line: use string versions of functionsDenton Liu, Jun 14, 2020
  10. Junio C HamanoJun 14, 2020
  11. Denton LiuJun 14, 2020
  12. Đoàn Trần Công DanhJun 15, 2020
  13. 1/3 remote-curl: use strlen() instead of magic numbersDenton Liu, Jun 14, 2020
  14. 3/3 pkt-line: extract out PACKET_HEADER_SIZEDenton Liu, Jun 14, 2020
  15. Junio C HamanoJun 14, 2020
  16. 0/3 pkt-line: war on magical `4` literalDenton Liu, Jun 23, 2020
  17. 1/3 remote-curl: use strlen() instead of magic numbersDenton Liu, Jun 23, 2020
  18. Jeff KingJun 23, 2020
  19. Junio C HamanoJun 23, 2020
  20. 2/3 pkt-line: use string versions of functionsDenton Liu, Jun 23, 2020
  21. Jeff KingJun 23, 2020
  22. 3/3 pkt-line: extract out PACKET_HEADER_SIZEDenton Liu, Jun 23, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.