From patchwork Tue Jan 19 19:35:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 10472 Received: (qmail 19221 invoked by alias); 19 Jan 2016 19:36:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 19201 invoked by uid 89); 19 Jan 2016 19:36:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.1 required=5.0 tests=AWL, BAYES_40, SPF_HELO_PASS, SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=HX-Greylist:succeeded, HX-Greylist:SMTP, HX-Greylist:AUTH, KERN_PROC X-HELO: bigwig.baldwin.cx Received: from bigwig.baldwin.cx (HELO bigwig.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Tue, 19 Jan 2016 19:36:14 +0000 Received: from ralph.baldwin.cx (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 4CE04B946; Tue, 19 Jan 2016 14:36:12 -0500 (EST) From: John Baldwin To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Use a separate variable for the size passed to sysctl. Date: Tue, 19 Jan 2016 11:35:55 -0800 Message-ID: <1679587.CEfXXqWAZn@ralph.baldwin.cx> User-Agent: KMail/4.14.3 (FreeBSD/10.2-STABLE; KDE/4.14.3; amd64; ; ) In-Reply-To: <569E8C19.5060206@redhat.com> References: <1453227896-65820-1-git-send-email-jhb@FreeBSD.org> <569E8C19.5060206@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes 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 > > > > + * 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