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

[PATCH] http-walker: simplify process_alternates_response() using strbuf

From
René Scharfe <l.s.r@web.de>
Date
Aug 30, 2014, 15:55 UTC
Message-ID
<5401F401.8040607@web.de>

Use strbuf to build the new base, which takes care of allocations and the terminating NUL character automatically.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 http-walker.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/http-walker.c b/http-walker.c
index dbddfaa..88da546 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -230,7 +230,6 @@ static void process_alternates_response(void *callback_data)
 			int okay = 0;
 			int serverlen = 0;
 			struct alt_base *newalt;
-			char *target = NULL;
 			if (data[i] == '/') {
 				/*
 				 * This counts
@@ -287,17 +286,15 @@ static void process_alternates_response(void *callback_data)
 			}
 			/* skip "objects\n" at end */
 			if (okay) {
-				target = xmalloc(serverlen + posn - i - 6);
-				memcpy(target, base, serverlen);
-				memcpy(target + serverlen, data + i,
-				       posn - i - 7);
-				target[serverlen + posn - i - 7] = 0;
+				struct strbuf target = STRBUF_INIT;
+				strbuf_add(&target, base, serverlen);
+				strbuf_add(&target, data + i, posn - i - 7);
 				if (walker->get_verbosely)
-					fprintf(stderr,
-						"Also look at %s\n", target);
+					fprintf(stderr, "Also look at %s\n",
+						target.buf);
 				newalt = xmalloc(sizeof(*newalt));
 				newalt->next = NULL;
-				newalt->base = target;
+				newalt->base = strbuf_detach(&target, NULL);
 				newalt->got_indices = 0;
 				newalt->packs = NULL;
 
-- 
2.1.0
Message 1 of 1 in “http-walker: simplify process_alternates_response() using strbuf”
  1. http-walker: simplify process_alternates_response() using strbufRené Scharfe, Aug 30, 2014

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.