http-walker: simplify process_alternates_response() using strbuf
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Aug 30, 2014 at 17:55 UTC
59b8263a6dc3946b62101a9cc9c603a5486cee09
1 file changed
+6
-9
http-walker.c
+6
-9
@@ -230,7 +230,6 @@ static void process_alternates_response(void *callback_data)
230
int okay = 0;
231
int serverlen = 0;
232
struct alt_base *newalt;
233
- char *target = NULL;
233
if (data[i] == '/') {
234
/*
235
* This counts
@@ -287,17 +286,15 @@ static void process_alternates_response(void *callback_data)
286
}
287
/* skip "objects\n" at end */
288
if (okay) {
290
- target = xmalloc(serverlen + posn - i - 6);
291
- memcpy(target, base, serverlen);
292
- memcpy(target + serverlen, data + i,
293
- posn - i - 7);
294
- target[serverlen + posn - i - 7] = 0;
289
+ struct strbuf target = STRBUF_INIT;
290
+ strbuf_add(&target, base, serverlen);
291
+ strbuf_add(&target, data + i, posn - i - 7);
292
if (walker->get_verbosely)
296
- fprintf(stderr,
297
- "Also look at %s\n", target);
293
+ fprintf(stderr, "Also look at %s\n",
294
+ target.buf);
295
newalt = xmalloc(sizeof(*newalt));
296
newalt->next = NULL;
300
- newalt->base = target;
297
+ newalt->base = strbuf_detach(&target, NULL);
298
newalt->got_indices = 0;
299
newalt->packs = NULL;
300