This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 4/7] Introduce linux_pid_to_exec_file


Doug Evans wrote:
> On Tue, Apr 7, 2015 at 2:07 AM, Gary Benson <gbenson@redhat.com> wrote:
> > Doug Evans wrote:
> > > Gary Benson <gbenson@redhat.com> writes:
> > > > +/* See nat/linux-nat.h.  */
> > > > +
> > > > +char *
> > > > +linux_pid_to_exec_file (int pid)
> > > > +{
> > > > +  static char buf[PATH_MAX];
> > > > +  char name[PATH_MAX];
> > > > +
> > > > +  xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
> > > > +  memset (buf, 0, PATH_MAX);
> > > > +  if (readlink (name, buf, PATH_MAX - 1) <= 0)
> > > > +    strcpy (buf, name);
> > > > +
> > > > +  return buf;
> > > > +}
> 
> Hi. Another nit.
> 
> Since readlink does not nul-terminate the string, I think it would
> be clearer to explicitly nul-terminate the result instead of doing
> the initial memset. I realize the current linux-nat.c version
> doesn't do this, but we can still improve things here.

Ok, I'll do that.

> [One might also want the code to protect itself in the case where
> the buf is not large enough, but one can leave that for now since
> we assume PATH_MAX is big enough throughout.]

I don't know how you'd tell, readlink doesn't seem to indicate whether
it truncated or not.

Cheers,
Gary

-- 
http://gbenson.net/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]