From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26066 invoked by alias); 26 Nov 2012 16:33:48 -0000 Received: (qmail 25955 invoked by uid 22791); 26 Nov 2012 16:33:45 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,MSGID_MULTIPLE_AT,TW_XZ X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.152) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 26 Nov 2012 16:33:36 +0000 Received: from md13.u-strasbg.fr (md13.u-strasbg.fr [130.79.200.248]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id qAQGXVrP065105 ; Mon, 26 Nov 2012 17:33:31 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms17.u-strasbg.fr [130.79.204.117]) by md13.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id qAQGXUTA014105 ; Mon, 26 Nov 2012 17:33:30 +0100 (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from E6510Muller (gw-ics.u-strasbg.fr [130.79.210.225]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id qAQGXT6g030409 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) ; Mon, 26 Nov 2012 17:33:29 +0100 (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: "'Pedro Alves'" Cc: , References: <20121126142036.10142.97678.stgit@brno.lan> <004401cdcbe4$524136c0$f6c3a440$@muller@ics-cnrs.unistra.fr> <50B38790.5090206@redhat.com> <005301cdcbeb$1b177e50$51467af0$@muller@ics-cnrs.unistra.fr> <50B38E82.1020102@redhat.com> In-Reply-To: <50B38E82.1020102@redhat.com> Subject: RE: [PATCH] Fix readlink calls in GDB Date: Mon, 26 Nov 2012 16:33:00 -0000 Message-ID: <000301cdcbf3$c49234e0$4db69ea0$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-11/txt/msg00663.txt.bz2 > -----Message d'origine----- > De : gdb-patches-owner@sourceware.org [mailto:gdb-patches- > owner@sourceware.org] De la part de Pedro Alves > Envoy=C3=A9 : lundi 26 novembre 2012 16:45 > =C3=80 : Pierre Muller > Cc : gdb-patches@sourceware.org; rustyBSD@gmx.fr > Objet : Re: [PATCH] Fix readlink calls in GDB >=20 > On 11/26/2012 03:31 PM, Pierre Muller wrote: > > I don't see any code setting the terminal char to '\0' > > in fbsd_pid_to_exec_file (fbsd-nat.c:40 rev 1.29) >=20 > char * > fbsd_pid_to_exec_file (int pid) > { > size_t len =3D MAXPATHLEN; > char *buf =3D xcalloc (len, sizeof (char)); > ^^^^^^^ > char *path; >=20 > xcalloc memsets the memory to zero before returning. See man calloc. Thank you for the answers, I am sorry to have wasted your time :( I didn't know calloc was zeroing data... =20 =20 > > nor in linux_child_pid_to_exec_file (linux-nat.c:4311 rev 1.261) >=20 > static char * > linux_child_pid_to_exec_file (int pid) > { > char *name1, *name2; >=20 > name1 =3D xmalloc (MAXPATHLEN); > name2 =3D xmalloc (MAXPATHLEN); > make_cleanup (xfree, name1); > make_cleanup (xfree, name2); > memset (name2, 0, MAXPATHLEN); > ^^^^^^ > > That memset clear the whole buffer, thus the buffer ends up > always nul-terminated. I completely missed that memset call :( Does that mean that name2 =3D xzalloc (MAXPATHLEN); or name2 =3D xcalloc (MAXPATHLEN, 1); could have replaced the two lines: > name2 =3D xmalloc (MAXPATHLEN); > memset (name2, 0, MAXPATHLEN); =20=20 Thank you again for taking the time to=20 answer my questions... Pierre Muller