Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Pedro Alves <alves.ped@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [commit/Tru64] bring back the Tru64 port to life...
Date: Fri, 06 Mar 2009 00:58:00 -0000	[thread overview]
Message-ID: <20090306005753.GG3744@adacore.com> (raw)
In-Reply-To: <200903060028.40871.alves.ped@gmail.com>

> Can nsecs be 0 here?

Good question. It seems pretty highly unlikely, but I'm not sure whether
this is possible or not. I couldn't find a whole lot of documentation
about the lmi_nregion field in ldr_module_info_t. But from the code
in solib-osf.c, it looks like this field is actually the number of
sections. I don't see how a shared library could have zero section
and yet still be loaded. If the naming in solib-osf.c got me
confused, and the secs array actually refers to memory regions,
you'd think that there would be at least one region for the code.

> Since it is checked at least here:

Yeah, that's strange.

I can add an extra check, but...

> struct lm_info
>   {
>     int isloader;               /* whether the module is /sbin/loader */
>     int nsecs;                  /* length of .secs */
>     struct lm_sec secs[1];      /* variable-length array of sections, sorted
>                                    by name */
>   };

The previous code was a glorified version of 

   malloc (offsetof (struct lm_info, secs)
           + nsecs * sizeof (struct lm_sec))

The new expression I used should be strictly equivalent:

  malloc (sizeof (struct lm_info)
          + (nsecs - 1) * sizeof (struct lm_sec));

In both cases, if nsecs is zero, we end up allocating less memory
than sizeof (struct lm_info). Intuitively, it seems OK, since we
shouldn't really access the secs array if nsecs is null.

One easy way out is to change the allocation to allocate one extra
entry in the secs array. It's slightly wasteful, but it's just a
few bytes times the number of shared libraries.

What do you think?

-- 
Joel


  reply	other threads:[~2009-03-06  0:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-05 23:55 Joel Brobecker
2009-03-06  0:28 ` Pedro Alves
2009-03-06  0:58   ` Joel Brobecker [this message]
2009-03-06  1:00     ` 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=20090306005753.GG3744@adacore.com \
    --to=brobecker@adacore.com \
    --cc=alves.ped@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /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