From: Karthik Nayak Date: Thu, 10 Sep 2015 18:04:42 GMT Subject: Re: [PATCH v17 13/14] tag.c: implement '--format' option Message-ID: In-Reply-To: On Thu, Sep 10, 2015 at 11:29 PM, Junio C Hamano wrote: > 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? > Seems like I didn't run the tests here, will change this. >> + 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. Yeah! -- Regards, Karthik Nayak