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


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.

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

> nor in nbsd_pid_to_exec_file (nbsd-nat.c:30 rev 1.10)...

That likewise uses xcalloc.

-- 
Pedro Alves


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