(_AT_TEST_GLR_CALC): Include stdlib.h, since

we use malloc.  Don't assume 'A' through 'Z' are contiguous.
Don't assume strdup exists; POSIX says its an XSI extension.
Check for buffer overflow on input.
This commit is contained in:
Paul Eggert
2002-10-25 05:13:24 +00:00
parent b526ee6116
commit c469accea7

View File

@@ -88,6 +88,7 @@ declarator : ID { printf ("\"%s\" ", ]$[1); }
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
int int
@@ -111,24 +112,39 @@ yylex ()
{ {
char buffer[256]; char buffer[256];
int c; int c;
unsigned int i;
#if YYPURE #if YYPURE
# define yylval (*lvalp) # define yylval (*lvalp)
]m4_bmatch([$1], [location],[ (void) llocp;])[ ]m4_bmatch([$1], [location],[ (void) llocp;])[
#endif #endif
while (1) { while (1)
{
c = getchar (); c = getchar ();
switch (c) { switch (c)
{
case EOF: case EOF:
return 0; return 0;
case ' ': case '\t': case '\n': case '\f': case ' ': case '\t': case '\n': case '\f':
break; break;
default: default:
if (isalpha (c)) { if (isalpha (c))
{
i = 0;
do
{
buffer[i++] = c;
if (i == sizeof buffer - 1)
abort ();
c = getchar ();
}
while (isalnum (c) || c == '_');
ungetc (c, stdin); ungetc (c, stdin);
scanf ("%[A-Za-z0-9_]", buffer); buffer[i++] = 0;
yylval = strdup (buffer); yylval = strcpy (malloc (i), buffer);
return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID; return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
} }
return c; return c;