From c51a351a6bcc64ad8cb2ed5a6ebde54b8d50eef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Fri, 18 May 2012 07:15:17 +0200 Subject: [PATCH 1/2] archive: simplify refname handling There is no need to build a copy of the relevant part of the string just to make sure we have a NUL-terminated string. We can simply pass the length of the interesting part to dwim_ref() instead. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- archive.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/archive.c b/archive.c index 1ee837d717..1e7156d580 100644 --- a/archive.c +++ b/archive.c @@ -260,18 +260,11 @@ static void parse_treeish_arg(const char **argv, /* Remotes are only allowed to fetch actual refs */ if (remote) { char *ref = NULL; - const char *refname, *colon = NULL; - - colon = strchr(name, ':'); - if (colon) - refname = xstrndup(name, colon - name); - else - refname = name; - - if (!dwim_ref(refname, strlen(refname), sha1, &ref)) - die("no such ref: %s", refname); - if (refname != name) - free((void *)refname); + const char *colon = strchr(name, ':'); + int refnamelen = colon ? colon - name : strlen(name); + + if (!dwim_ref(name, refnamelen, sha1, &ref)) + die("no such ref: %.*s", refnamelen, name); free(ref); } From bf38245be8f481ac1c08a98951b7fd00bbfc15ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Fri, 18 May 2012 07:18:11 +0200 Subject: [PATCH 2/2] archive-tar: keep const in checksum calculation For correctness, don't needlessly drop the const qualifier when casting. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- archive-tar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archive-tar.c b/archive-tar.c index 20af0051a3..55cccecadf 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -101,13 +101,13 @@ static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword, static unsigned int ustar_header_chksum(const struct ustar_header *header) { - char *p = (char *)header; + const char *p = (const char *)header; unsigned int chksum = 0; while (p < header->chksum) chksum += *p++; chksum += sizeof(header->chksum) * ' '; p += sizeof(header->chksum); - while (p < (char *)header + sizeof(struct ustar_header)) + while (p < (const char *)header + sizeof(struct ustar_header)) chksum += *p++; return chksum; }