From c469accea717bf6e9750fed8c4d4a1d356aca184 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 25 Oct 2002 05:13:24 +0000 Subject: [PATCH] (_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. --- tests/cxx-type.at | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/tests/cxx-type.at b/tests/cxx-type.at index df85fd7..25abfd5 100644 --- a/tests/cxx-type.at +++ b/tests/cxx-type.at @@ -88,6 +88,7 @@ declarator : ID { printf ("\"%s\" ", ]$[1); } #include #include +#include #include int @@ -111,29 +112,44 @@ yylex () { char buffer[256]; int c; + unsigned int i; #if YYPURE # define yylval (*lvalp) ]m4_bmatch([$1], [location],[ (void) llocp;])[ #endif - while (1) { - c = getchar (); - switch (c) { - case EOF: - return 0; - case ' ': case '\t': case '\n': case '\f': - break; - default: - if (isalpha (c)) { - ungetc (c, stdin); - scanf ("%[A-Za-z0-9_]", buffer); - yylval = strdup (buffer); - return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID; - } - return c; + while (1) + { + c = getchar (); + switch (c) + { + case EOF: + return 0; + case ' ': case '\t': case '\n': case '\f': + break; + default: + if (isalpha (c)) + { + i = 0; + + 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 -- 2.7.4