C++ PATCH: obstack leakage -> segfault

Nathan Sidwell nathan@acm.org
Wed May 26 02:43:00 GMT 1999


Hi,
I fell over a bug with array types where the type was allocated on the
permanent obstack and the TYPE_DOMAIN on a temporary one. When the the type was
copied to permanent, nothing changed and the compiler segfaulted later as the
domain got trashed. I attach an example which kills i686-pc-linux-gnu but not
sparc-sun-solaris2.6.

I attach a patch to complete_array_type (decl.c) which makes sure the domain is
placed in the permanent obstack, if anything it's being attached to is.
(Perhaps it should always be placed on the permanent obstack?)

The 2.95 branch has the same flaw (and segfaults on sparc-sun-solaris2.6). I
recommend that be fixed too.

May I install it?

nathan
-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
        I have seen the death of PhotoShop -- it is called GIMP
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk

typedef void (*Fptr)();

inline void NotUsed(Fptr) throw()
{
  return;
}

void Fn(Fptr const &);

template<class T> inline Fptr Foo(T const *)
{
  return &T::FnValue;
}

template<class T> inline Fptr Bar()
{
  return Foo((T const *)0);
}

template<class T> inline Fptr Quux(T const *const &)
{
  return Bar<T>();
}

template<class T> inline Fptr Quux(T const &objRef)
{
  return Quux(&objRef);
}

template<class T, unsigned I> void  FnArray ()
{}

template<class T, unsigned I> inline Fptr Foo(T const (*)[I])
{
  return &FnArray<T,I>;
}

int main(int, char *[])
{
  static int attribList[] = {2, 1, 0};
  Fn(Quux(attribList));
  return 0;
}


More information about the Gcc-patches mailing list