On Sat, 11 Jun 2016 09:28:09 +0900 Masami Hiramatsu <mhira...@kernel.org> wrote:
> On Thu, 9 Jun 2016 11:22:55 -0300 > Arnaldo Carvalho de Melo <a...@kernel.org> wrote: > > > Em Wed, Jun 08, 2016 at 06:30:30PM +0900, Masami Hiramatsu escreveu: > > > +char *build_id_cache__origname(const char *sbuild_id) > > > +{ > > > + char *linkname; > > > + char buf[PATH_MAX]; > > > + char *ret = NULL, *p; > > > + size_t offs = 5; /* == strlen("../..") */ > > > + > > > + linkname = build_id_cache__linkname(sbuild_id, NULL, 0); > > > + if (!linkname) > > > + return NULL; > > > + > > > + if (readlink(linkname, buf, PATH_MAX) < 0) > > > + goto out; > > > + /* The link should be "../..<origpath>/<sbuild_id>" */ > > > + p = strrchr(buf, '/'); /* Cut off the "/<sbuild_id>" */ > > > + if (p && (p > buf + offs)) { > > > + *p = '\0'; > > > + if (buf[offs + 1] == '[') > > > + offs++; /* > > > + * This is a DSO name, like [kernel.kallsyms]. > > > + * Skip the first '/', since this is not the > > > + * cache of a regular file. > > > + */ > > > + ret = strdup(buf + offs); /* Skip "../..[/]" */ > > > > strdup can fail. > > Ah, right. In this case, build_id_cache__origname() returns ret immediately(see below), so we don't need to take reaction about that :) > > > + } > > > +out: > > > + free(linkname); > > > + return ret; > > > +} here, if strdup() fails, this just return NULL. that is OK. Thanks! -- Masami Hiramatsu <mhira...@kernel.org>