From mboxrd@z Thu Jan 1 00:00:00 1970 From: cgit at cryptocrack.de (Lukas Fleischer) Date: Sun, 7 Apr 2013 14:49:40 +0200 Subject: [PATCH 19/19] ui-shared.c: use struct strbuf instead of fmt() In-Reply-To: References: <4015edb895155d4e092576383cfd790e02d4e197.1365326321.git.john@keeping.me.uk> Message-ID: <20130407124940.GA30921@blizzard> On Sun, Apr 07, 2013 at 02:37:09PM +0200, Jason A. Donenfeld wrote: > On Sun, Apr 7, 2013 at 11:30 AM, John Keeping wrote: > > const char *cgit_hosturl() > > { > > + struct strbuf sb = STRBUF_INIT; > > if (ctx.env.http_host) > > return ctx.env.http_host; > > if (!ctx.env.server_name) > > return NULL; > > if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80) > > return ctx.env.server_name; > > - return xstrdup(fmt("%s:%s", ctx.env.server_name, ctx.env.server_port)); > > + strbuf_addf(&sb, "%s:%s", ctx.env.server_name, ctx.env.server_port); > > + return strbuf_detach(&sb, NULL); > > } > > Constness issues, since we're going to want to perhaps deallocate this > at some point? cgit_hosturl() currently returns both statically and dynamically allocated strings (depending on the environment), so it needs to be rewritten/replaced if we want to free() this later anyway. The const return value isn't the real issue here. > > _______________________________________________ > cgit mailing list > cgit at hjemli.net > http://hjemli.net/mailman/listinfo/cgit