summaryrefslogtreecommitdiffstats
path: root/gcc/gengtype.c
diff options
context:
space:
mode:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2007-03-29 14:59:52 +0000
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2007-03-29 14:59:52 +0000
commit409f91752339f4adeeb1b3ebe4d58796a046ce78 (patch)
tree61160a7915c47c25ff4c806b91e20390af7d0393 /gcc/gengtype.c
parenta024c245d56bfab96b66ac194c638f9318bdbae7 (diff)
downloadppe42-gcc-409f91752339f4adeeb1b3ebe4d58796a046ce78.tar.gz
ppe42-gcc-409f91752339f4adeeb1b3ebe4d58796a046ce78.zip
* gengtype.c (oprintf): Mostly revert changes from 2007-03-26;
add comment explaining why vsnprintf cannot be used. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@123332 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gengtype.c')
-rw-r--r--gcc/gengtype.c39
1 files changed, 15 insertions, 24 deletions
diff --git a/gcc/gengtype.c b/gcc/gengtype.c
index e0cd6c2599f..648246dbd66 100644
--- a/gcc/gengtype.c
+++ b/gcc/gengtype.c
@@ -1475,24 +1475,26 @@ create_file (const char *name, const char *oname)
return f;
}
-/* Print, like fprintf, to O. */
+/* Print, like fprintf, to O.
+ N.B. You might think this could be implemented more efficiently
+ with vsnprintf(). Unfortunately, there are C libraries that
+ provide that function but without the C99 semantics for its return
+ value, making it impossible to know how much space is required. */
void
oprintf (outf_p o, const char *format, ...)
{
+ char *s;
size_t slength;
+ va_list ap;
- /* 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);
- }
+ va_start (ap, format);
+ slength = vasprintf (&s, format, ap);
+ if (s == NULL || (int)slength < 0)
+ fatal ("out of memory");
+ va_end (ap);
- if (o->bufused + slength >= o->buflength)
+ if (o->bufused + slength > o->buflength)
{
- /* There wasn't enough space. */
size_t new_len = o->buflength;
if (new_len == 0)
new_len = 1024;
@@ -1501,21 +1503,10 @@ oprintf (outf_p o, const char *format, ...)
} 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);
- }
}
+ memcpy (o->buf + o->bufused, s, slength);
o->bufused += slength;
+ free (s);
}
/* Open the global header file and the language-specific header files. */
OpenPOWER on IntegriCloud