public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Use a separate variable for the size passed to sysctl.
@ 2016-01-19 18:29 John Baldwin
  2016-01-19 19:18 ` Pedro Alves
  0 siblings, 1 reply; 4+ messages in thread
From: John Baldwin @ 2016-01-19 18:29 UTC (permalink / raw)
  To: gdb-patches

This fixes a sign mismatch warning.

gdb/ChangeLog:

	* fbsd-tdep.c (fbsd_pid_to_exec_file): Use new "buflen" instead of
	"len" with sysctl.
---
 gdb/ChangeLog  | 5 +++++
 gdb/fbsd-nat.c | 4 +++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e8277f3..aa7e0fa 100644
--- 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.
+
+2016-01-19  John Baldwin  <jhb@FreeBSD.org>
+
 	* fbsd-tdep.c (find_stop_signal): Remove.
 	(struct fbsd_collect_regset_section_cb) <lwp>: New field.
 	<stop_signal>: New field.
diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index d2ec527..6504625 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -48,13 +48,15 @@ fbsd_pid_to_exec_file (struct target_ops *self, int pid)
   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
 
-- 
2.7.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Use a separate variable for the size passed to sysctl.
  2016-01-19 18:29 [PATCH] Use a separate variable for the size passed to sysctl John Baldwin
@ 2016-01-19 19:18 ` Pedro Alves
  2016-01-19 19:36   ` John Baldwin
  0 siblings, 1 reply; 4+ messages in thread
From: Pedro Alves @ 2016-01-19 19:18 UTC (permalink / raw)
  To: John Baldwin, gdb-patches

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".

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Use a separate variable for the size passed to sysctl.
  2016-01-19 19:18 ` Pedro Alves
@ 2016-01-19 19:36   ` John Baldwin
  2016-01-19 22:53     ` Pedro Alves
  0 siblings, 1 reply; 4+ messages in thread
From: John Baldwin @ 2016-01-19 19:36 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Use a separate variable for the size passed to sysctl.
  2016-01-19 19:36   ` John Baldwin
@ 2016-01-19 22:53     ` Pedro Alves
  0 siblings, 0 replies; 4+ messages in thread
From: Pedro Alves @ 2016-01-19 22:53 UTC (permalink / raw)
  To: John Baldwin; +Cc: gdb-patches

On 01/19/2016 07:35 PM, John Baldwin wrote:
> 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:

Yes, of course.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-01-19 22:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-19 18:29 [PATCH] Use a separate variable for the size passed to sysctl John Baldwin
2016-01-19 19:18 ` Pedro Alves
2016-01-19 19:36   ` John Baldwin
2016-01-19 22:53     ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).