mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-22 02:33:03 +00:00
(_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:
@@ -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,29 +112,44 @@ 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 ();
|
{
|
||||||
switch (c) {
|
c = getchar ();
|
||||||
case EOF:
|
switch (c)
|
||||||
return 0;
|
{
|
||||||
case ' ': case '\t': case '\n': case '\f':
|
case EOF:
|
||||||
break;
|
return 0;
|
||||||
default:
|
case ' ': case '\t': case '\n': case '\f':
|
||||||
if (isalpha (c)) {
|
break;
|
||||||
ungetc (c, stdin);
|
default:
|
||||||
scanf ("%[A-Za-z0-9_]", buffer);
|
if (isalpha (c))
|
||||||
yylval = strdup (buffer);
|
{
|
||||||
return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
|
i = 0;
|
||||||
}
|
|
||||||
return c;
|
do
|
||||||
|
{
|
||||||
|
buffer[i++] = c;
|
||||||
|
if (i == sizeof buffer - 1)
|
||||||
|
abort ();
|
||||||
|
c = getchar ();
|
||||||
|
}
|
||||||
|
while (isalnum (c) || c == '_');
|
||||||
|
|
||||||
|
ungetc (c, stdin);
|
||||||
|
buffer[i++] = 0;
|
||||||
|
yylval = strcpy (malloc (i), buffer);
|
||||||
|
return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
Reference in New Issue
Block a user