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


On Tue, Apr 7, 2015 at 2:07 AM, Gary Benson <gbenson@redhat.com> wrote:
> Doug Evans wrote:
>> Gary Benson <gbenson@redhat.com> writes:
>> > diff --git a/gdb/nat/linux-nat.c b/gdb/nat/linux-nat.c
>> > new file mode 100644
>> > index 0000000..b9deae3
>> > --- /dev/null
>> > +++ b/gdb/nat/linux-nat.c
>> > @@ -0,0 +1,37 @@
> ...
>> > +/* 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.

[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.]


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