This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RE: [PATCH] Fix readlink calls in GDB
- From: "Pierre Muller" <pierre dot muller at ics-cnrs dot unistra dot fr>
- To: "'Pedro Alves'" <palves at redhat dot com>
- Cc: <gdb-patches at sourceware dot org>, <rustyBSD at gmx dot fr>
- Date: Mon, 26 Nov 2012 17:33:29 +0100
- Subject: RE: [PATCH] Fix readlink calls in GDB
- 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>
> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Pedro Alves
> Envoyà : lundi 26 novembre 2012 16:45
> Ã : Pierre Muller
> Cc : gdb-patches@sourceware.org; rustyBSD@gmx.fr
> Objet : Re: [PATCH] Fix readlink calls in GDB
>
> 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)
>
> char *
> fbsd_pid_to_exec_file (int pid)
> {
> size_t len = MAXPATHLEN;
> char *buf = xcalloc (len, sizeof (char));
> ^^^^^^^
> char *path;
>
> 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...
> > nor in linux_child_pid_to_exec_file (linux-nat.c:4311 rev 1.261)
>
> static char *
> linux_child_pid_to_exec_file (int pid)
> {
> char *name1, *name2;
>
> name1 = xmalloc (MAXPATHLEN);
> name2 = 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 = xzalloc (MAXPATHLEN);
or
name2 = xcalloc (MAXPATHLEN, 1);
could have replaced the two lines:
> name2 = xmalloc (MAXPATHLEN);
> memset (name2, 0, MAXPATHLEN);
Thank you again for taking the time to
answer my questions...
Pierre Muller