*** bison-1.25/main.c Sun Oct 15 09:44:08 1995 --- bison-1.25/main.c.s-max Sat Dec 12 23:46:02 1998 *************** *** 37,42 **** --- 37,75 ---- extern void output(), done(); + + + /* Return buffer after making sure it has at least sz bytes. If this + fails to allocate enough memory, it exits fatally -- which is + admittedly suboptimal, as it means that we won't print the error + message we were *really* trying to print. */ + static char * + get_buffer(size_t sz) + { + void fatal(char * s); + + static char * buffer = NULL; /* Buffer used for fatal/warning messages. */ + static size_t bufsz = 0; /* Size of space allocated by buffer. */ + + if (sz > bufsz) /* Need to expand buffer. */ + { + bufsz = sz; /* Expand it just enough. */ + + /* If GNU realloc() gets a NULL first arg, it acts like + malloc(), but I don't think that's required by the standard, + so other environments might need it done this way: */ + buffer = buffer ? realloc(buffer, bufsz) : malloc(bufsz); + + if (!buffer) + fatal("Out of memory in get_buffer()."); + } + + return buffer; + } + + + + /* VMS complained about using `int'. */ int *************** *** 144,150 **** fatals(fmt, x1) char *fmt, *x1; { ! char buffer[200]; sprintf(buffer, fmt, x1); fatal(buffer); } --- 177,184 ---- fatals(fmt, x1) char *fmt, *x1; { ! char * const buffer = get_buffer(strlen(fmt) + strlen(x1)); ! sprintf(buffer, fmt, x1); fatal(buffer); } *************** *** 174,180 **** char *fmt; int x1; { ! char buffer[200]; sprintf(buffer, fmt, x1); warn(buffer); } --- 208,216 ---- char *fmt; int x1; { ! /* Add 20 to cover the %d. */ ! char * const buffer = get_buffer(strlen(fmt) + 20); ! sprintf(buffer, fmt, x1); warn(buffer); } *************** *** 186,192 **** warns(fmt, x1) char *fmt, *x1; { ! char buffer[200]; sprintf(buffer, fmt, x1); warn(buffer); } --- 222,229 ---- warns(fmt, x1) char *fmt, *x1; { ! char * const buffer = get_buffer(strlen(fmt) + strlen(x1)); ! sprintf(buffer, fmt, x1); warn(buffer); } *************** *** 198,204 **** warnss(fmt, x1, x2) char *fmt, *x1, *x2; { ! char buffer[200]; sprintf(buffer, fmt, x1, x2); warn(buffer); } --- 235,242 ---- warnss(fmt, x1, x2) char *fmt, *x1, *x2; { ! char * const buffer = get_buffer(strlen(fmt) + strlen(x1) + strlen(x2)); ! sprintf(buffer, fmt, x1, x2); warn(buffer); } *************** *** 210,216 **** warnsss(fmt, x1, x2, x3) char *fmt, *x1, *x2, *x3; { ! char buffer[200]; sprintf(buffer, fmt, x1, x2, x3); warn(buffer); } --- 248,256 ---- warnsss(fmt, x1, x2, x3) char *fmt, *x1, *x2, *x3; { ! char * const buffer = get_buffer(strlen(fmt) + ! strlen(x1) + strlen(x2) + strlen(x3)); ! sprintf(buffer, fmt, x1, x2, x3); warn(buffer); } *************** *** 222,229 **** toomany(s) char *s; { ! char buffer[200]; ! sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s); fatal(buffer); } --- 262,272 ---- toomany(s) char *s; { ! static char fmt[] = "limit of %d exceeded, too many %s"; ! /* Add 20 to cover the %d. */ ! char * const buffer = get_buffer(strlen(fmt) + strlen(s) + 20); ! ! sprintf(buffer, fmt, MAXSHORT, s); fatal(buffer); }