On Fri, 2012-05-18 at 11:59 -0400, Jeff King wrote: > [+cc Carlos, as this is his code] > > On Fri, May 18, 2012 at 07:15:17AM +0200, René Scharfe wrote: > > > 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 <rene.scharfe@xxxxxxxxxxxxxx> > > --- > > archive.c | 17 +++++------------ > > 1 file changed, 5 insertions(+), 12 deletions(-) > > > > diff --git a/archive.c b/archive.c > > index cd083ea..ecc1ff0 100644 > > --- a/archive.c > > +++ b/archive.c > > @@ -254,18 +254,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, ':'); > > + size_t refnamelen = colon ? colon - name : strlen(name); > > + > > + if (!dwim_ref(name, refnamelen, sha1, &ref)) > > + die("no such ref: %.*s", refnamelen, name); > > free(ref); > > Looks obviously correct to me. Yep, that's clearly a much better way of doing it. cmn -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html