Re: [perf/core PATCH v2 2/4] perf buildid-cache: Consolidate .build-id cache path generators

Arnaldo Carvalho de Melo
2015-02-11T14:46:00Z

Em Tue, Feb 10, 2015 at 06:18:53PM +0900, Masami Hiramatsu escreveu:
> +static int asnprintf(char **strp, size_t size, const char *fmt, ...)
> +{
> + va_list ap;
> + int ret;
> + if (!strp)
> + return -EINVAL;
> + va_start(ap, fmt);
> + if (*strp)
> + ret = vsnprintf(*strp, size, fmt, ap);
> + else
> + ret = vasprintf(strp, fmt, ap);
> + va_end(ap);
> + return ret;
> +}
> +static char *build_id__filename(const char *sbuild_id, char *bf, size_t size)
> +{
> + char *tmp = bf;
> + int ret = asnprintf(&bf, size, "%s/.build-id/%.2s/%s", buildid_dir,
> + sbuild_id, sbuild_id + 2);
> + if (ret < 0 || (tmp && size < (unsigned int)ret))
> + return NULL;

This is a good thing, i.e. checking if the formatting truncated
something, i.e. vsnprintf honours 'size' but may return more than that,
but next time try to get it into a separate patch :-)

Anyway, after scratching my head with this extra thing/re-reading the
vsnprintf man page, I'm applying this patch, thanks.

- Arnaldo