This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: fyi: gengtype patches checked in
Steve Ellcey wrote:
> gengtype is seg faulting on IA64 HP-UX. It looks like oprintf in
> gcc/gengtype.c is calling vsnprintf when o->buf is NULL and expecting it
> to return zero and then fix things up later. On IA64 HP-UX the call to
> vsnprintf is giving a seg fault when o->buf is NULL.
>
> I tried putting that chunk of code in side "if (o->buf)" and
> initializing slength to zero but now I hit the "gcc_assert (slen2 ==
> slength)" and wind up stopping there.
You just have to create the buffer with a fixed length if it is
NULL, like this (untested):
size_t slength;
va_list ap;
va_start (ap, format);
if (!o->buf)
{
o->buf = XNEWVEC (char, 1024);
o->buflength = 1024;
}
/* Try first with the assumption that there is enough space. */
{
va_list ap;
va_start (ap, format);
slength = vsnprintf (o->buf + o->bufused, o->buflength - o->bufused,
format, ap);
va_end (ap);
}
if (o->bufused + slength >= o->buflength)
{
/* There wasn't enough space. */
size_t new_len = o->buflength;
do
new_len *= 2;
while (o->bufused + slength >= new_len);
o->buf = XRESIZEVEC (char, o->buf, new_len);
o->buflength = new_len;
/* We now know that there is enough space. */
{
size_t slen2;
va_list ap;
va_start (ap, format);
slen2 = vsnprintf (o->buf + o->bufused, o->buflength - o->bufused,
format, ap);
va_end (ap);
gcc_assert (slen2 == slength);
gcc_assert (o->bufused + slen2 < o->buflength);
}
}
o->bufused += slength;