From: Jeff King Date: Wed, 21 Sep 2016 11:09:35 GMT Subject: Re: [PATCH v2 2/2] mailinfo: unescape quoted-pair in header fields Message-ID: <20160921110934.f6eu2dz6i2mlpa45@sigill.intra.peff.net> In-Reply-To: <20160919185440.18234-3-me@ikke.info> On Mon, Sep 19, 2016 at 08:54:40PM +0200, Kevin Daudt wrote: > diff --git a/mailinfo.c b/mailinfo.c > index e19abe3..6a7c2f2 100644 > --- a/mailinfo.c > +++ b/mailinfo.c > @@ -54,6 +54,50 @@ static void parse_bogus_from(struct mailinfo *mi, const struct strbuf *line) > get_sane_name(&mi->name, &mi->name, &mi->email); > } > > +static void unquote_quoted_string(struct strbuf *line) > +{ > + const char *in = strbuf_detach(line, NULL); I see that this version uses the "detach, and then write into the replacement" approach, which is good. But... > + int c, take_next_literally = 0; > + int found_error = 0; > + > + /* > + * Stores the character that started the escape mode so that we know what > + * character will stop it > + */ > + char escape_context = 0; > + > + while ((c = *in++) != 0) { > + if (take_next_literally) { > + take_next_literally = 0; > + } else { > [...] > + } > + > + strbuf_addch(line, c); > + } > +} It needs to `free(in)` at the end of the function. Your original also fed "line->len" as a hint, but I doubt it really matters in practice, so I don't mind losing that. -Peff