This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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: Fix obscure obstack bug


I finally looked at this and don't see anthing wrong with the current
code.  Instead, your test program is faulty:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void *
my_alloc (size_t size)
{
  /* Grow the chunks up to a point.  */
#if SHOW_BUG
  if (obstack_chunk_size (&ob) < 100 * 1024)
    obstack_chunk_size (&ob) += 4 * 1024;
#endif
  return malloc (size);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You increase the chunk size but don't allocate enough memory.  You
want to compensate for this by changing the obstack code to not look
at the current chunk size and instead use what was previously
computed.  That's wrong and can break existing code.

If you want to fuzz around with the chunk size change the last line of
your function to

  return malloc (obstack_chunk_size (&ob));

This way you can control the chunk size and the changes are
automatically picked up in the obstack functions.  With your patch
applied this wouldn't be the case.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------


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