From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
To: "'Pedro Alves'" <palves@redhat.com>
Cc: <gdb-patches@sourceware.org>, <rustyBSD@gmx.fr>
Subject: RE: [PATCH] Fix readlink calls in GDB
Date: Mon, 26 Nov 2012 16:33:00 -0000 [thread overview]
Message-ID: <000301cdcbf3$c49234e0$4db69ea0$@muller@ics-cnrs.unistra.fr> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2012-11-26 16:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-26 14:20 Pedro Alves
2012-11-26 14:43 ` Pierre Muller
2012-11-26 15:16 ` Pedro Alves
2012-11-26 15:31 ` Pierre Muller
2012-11-26 16:12 ` Pedro Alves
2012-11-26 16:33 ` Pierre Muller [this message]
2012-11-26 16:54 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='000301cdcbf3$c49234e0$4db69ea0$@muller@ics-cnrs.unistra.fr' \
--to=pierre.muller@ics-cnrs.unistra.fr \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
--cc=rustyBSD@gmx.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox