This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: [PATCH] Fix readlink calls in GDB



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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]