This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Use a separate variable for the size passed to sysctl.
- From: John Baldwin <jhb at freebsd dot org>
- To: Pedro Alves <palves at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Tue, 19 Jan 2016 11:35:55 -0800
- Subject: Re: [PATCH] Use a separate variable for the size passed to sysctl.
- Authentication-results: sourceware.org; auth=none
- References: <1453227896-65820-1-git-send-email-jhb at FreeBSD dot org> <569E8C19 dot 5060206 at redhat dot com>
On Tuesday, January 19, 2016 07:18:49 PM Pedro Alves wrote:
> OK with ...
>
> On 01/19/2016 06:24 PM, John Baldwin wrote:
> > --- a/gdb/ChangeLog
> > +++ b/gdb/ChangeLog
> > @@ -1,5 +1,10 @@
> > 2016-01-19 John Baldwin <jhb@FreeBSD.org>
> >
> > + * fbsd-tdep.c (fbsd_pid_to_exec_file): Use new "buflen" instead of
> > + "len" with sysctl.
>
> ... should be "fbsd-nat.c".
Err, yes. I also noticed after mailing that the 'len' variable is now
initialized unnecessarily (since it's value is always overwritten by the
call to readlink() after the #endif). Is it ok to push this modified
version:
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -43,18 +43,20 @@
static char *
fbsd_pid_to_exec_file (struct target_ops *self, int pid)
{
- ssize_t len = PATH_MAX;
+ ssize_t len;
static char buf[PATH_MAX];
char name[PATH_MAX];
#ifdef KERN_PROC_PATHNAME
+ size_t buflen;
int mib[4];
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PATHNAME;
mib[3] = pid;
- if (sysctl (mib, 4, buf, &len, NULL, 0) == 0)
+ buflen = sizeof buf;
+ if (sysctl (mib, 4, buf, &buflen, NULL, 0) == 0)
return buf;
#endif
--
John Baldwin