Junio C Hamano <gitster@xxxxxxxxx> 写道: > > "Lidong Yan via GitGitGadget" <gitgitgadget@xxxxxxxxx> writes: > >> -static struct strbuf *decode_q_segment(const struct strbuf *q_seg, int rfc2047) >> +static int decode_q_segment(struct strbuf *out, const struct strbuf *q_seg, >> + int rfc2047) >> { >> const char *in = q_seg->buf; >> int c; >> - struct strbuf *out = xmalloc(sizeof(struct strbuf)); >> - strbuf_init(out, q_seg->len); >> + strbuf_grow(out, q_seg->len); > > Call to grow(), while it does not hurt correctness, would not be > necessary here, but let's take this code as-is. As the result of Q > encoding (and B encoding as well) always is longer than the decoded > result, strbuf_grow(out, q_seg->len) would always be over-allocating, > but it would not hurt too much. Thanks for your advice. Though I think `strbuf_init(out, q_seg->len)` also call `strbuf_grow` to reserve `q_seg->len` size memory for `out`. `strbuf_grow` here prevent multiple realloc operations that might occur when calling `strbuf_addch`.