[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GLR and strdup (Was: [GNU Bison 1.75a] testsuite: 89 90 91 92 93 94
From: |
Paul Eggert |
Subject: |
Re: GLR and strdup (Was: [GNU Bison 1.75a] testsuite: 89 90 91 92 93 94 95 96 97 failed) |
Date: |
Thu, 24 Oct 2002 22:17:36 -0700 (PDT) |
> From: Akim Demaille <address@hidden>
> Date: 24 Oct 2002 13:32:45 +0200
>
> I would suggest that the test suite itself provide the portability
> glue, not the skeleton.
I agree. But often it'll be easier to rewrite the tests to avoid the
portability problems.
I installed the following patch to fix this particular problem, along
with some other portability problems that I noticed while I was in the
neighborhood.
2002-10-24 Paul Eggert <address@hidden>
* tests/calc.at (_AT_DATA_CALC_Y): Remove unused strcat declaration.
* tests/cxx-type.at (_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 it's an XSI extension.
Check for buffer overflow on input.
Index: tests/calc.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/calc.at,v
retrieving revision 1.36
diff -p -u -r1.36 calc.at
--- tests/calc.at 20 Oct 2002 16:09:47 -0000 1.36
+++ tests/calc.at 25 Oct 2002 05:08:48 -0000
@@ -49,8 +49,6 @@ AT_DATA([calc.y],
#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
-#else
-char *strcat(char *dest, const char *src);
#endif
#include <ctype.h>
#include <assert.h>
Index: tests/cxx-type.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/cxx-type.at,v
retrieving revision 1.5
diff -p -u -r1.5 cxx-type.at
--- tests/cxx-type.at 14 Oct 2002 08:43:36 -0000 1.5
+++ tests/cxx-type.at 25 Oct 2002 05:08:48 -0000
@@ -88,6 +88,7 @@ declarator : ID { printf ("\"%s\" ", ]$
#include <assert.h>
#include <ctype.h>
+#include <stdlib.h>
#include <string.h>
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
Re: GLR and strdup (Was: [GNU Bison 1.75a] testsuite: 89 90 91 92 93 94 95 96 97 failed),
Paul Eggert <=