From: Junio C Hamano Date: Thu, 10 Sep 2015 17:59:37 GMT Subject: Re: [PATCH v17 13/14] tag.c: implement '--format' option Message-ID: In-Reply-To: <1441902169-9891-2-git-send-email-Karthik.188@gmail.com> Karthik Nayak writes: > -static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting) > +static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format) > { > struct ref_array array; > - char *format, *to_free = NULL; > + char *to_free = NULL; > int i; format is const char * while to_free is non-const char * here. > @@ -41,12 +41,14 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting) > if (filter->lines == -1) > filter->lines = 0; > > + if (!format) { > + if (filter->lines) { > + format = xstrfmt("%s %%(contents:lines=%d)", > + "%(align:15)%%(refname:short)%%(end)", filter->lines); Hmmm, did this even pass tests and if so how? What are these double %% doing before refname and end? Perhaps we do not have enough test coverage? > + to_free = format; This assignment discards constness. Take the result of xstrfmt() to to_free (which is a non-const pointer) and then assigning it to format (which is a const pointer) would work it around.