From mboxrd@z Thu Jan 1 00:00:00 1970 From: john at keeping.me.uk (John Keeping) Date: Sun, 7 Apr 2013 13:36:22 +0100 Subject: [PATCH 14/19] ui-summary.c: use struct strbuf instead of fixed-size buffers In-Reply-To: References: <4dd4fc55af2528bc676893c2bff8163d7f7d21d5.1365326321.git.john@keeping.me.uk> Message-ID: <20130407123622.GY2222@serenity.lan> On Sun, Apr 07, 2013 at 02:20:26PM +0200, Jason A. Donenfeld wrote: > On Sun, Apr 7, 2013 at 11:30 AM, John Keeping wrote: > > /* Prepend repo path to relative readme path unless tracked. */ > > - if (!ref && *ctx.repo->readme != '/') > > - ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, > > - ctx.repo->readme)); > > + if (!ref && *ctx.repo->readme != '/') { > > + struct strbuf buf = STRBUF_INIT; > > + strbuf_addf(&buf, "%s/%s", ctx.repo->path, ctx.repo->readme); > > + ctx.repo->readme = strbuf_detach(&buf, NULL); > > + } > > I do in fact see the merits of using strbuf and the purpose of this > patch set, but OTOH, this little chunk here illustrates the downsides > -- the extra verbosity this adds is really a bummer. Perhaps this > could be moved into a new fmtalloc helper function, if this pattern is > common? That could be sensible. I didn't do that initially because a lot of the uses are just: allocate format use free and there is no real saving from a helper in that case, but in case where we format an then detach the helper could be useful. I'll do that in the reroll.