From c83425ef4e1c66c81d328338e6bf98f5e3c33b81 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 23 Oct 2021 06:01:44 +0200 Subject: [PATCH] tests: address portability issues about strdup Reported by Dennis Clarke . In particular . * doc/bison.texi, examples/c/glr/c++-types.y, * examples/c/bistromathic/parse.y tests/testsuite.h: Define _XOPEN_SOURCE to 600, to get a strdup that works on Solaris. * tests/glr-regression.at: Use strdup freely. --- doc/bison.texi | 9 ++++++++- examples/c/bistromathic/parse.y | 5 +++++ examples/c/glr/c++-types.y | 4 ++++ tests/glr-regression.at | 4 +--- tests/testsuite.h | 5 +++++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/doc/bison.texi b/doc/bison.texi index a559649c..77357813 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -2644,6 +2644,13 @@ calculator. You should have received a copy of the GNU General Public License along with this program. If not, see . */ + +%code top { + /* Portability issues for strdup. */ +#ifndef _XOPEN_SOURCE +# define _XOPEN_SOURCE 600 +#endif +} @end example @end ignore @@ -2875,7 +2882,7 @@ found, a pointer to that symbol is returned; otherwise zero is returned. not make these assumptions. */ #include #include /* malloc, realloc. */ -#include /* strlen. */ +#include /* strdup, strlen. */ @end group @group diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y index fbdeb7fc..5c1e6055 100644 --- a/examples/c/bistromathic/parse.y +++ b/examples/c/bistromathic/parse.y @@ -21,6 +21,11 @@ // Emitted on top of the implementation file. %code top { + /* Portability issues for strdup. */ + #ifndef _XOPEN_SOURCE + # define _XOPEN_SOURCE 600 + #endif + #include // isdigit #include // LC_ALL #include // cos, sin, etc. diff --git a/examples/c/glr/c++-types.y b/examples/c/glr/c++-types.y index 4c978386..ff1b62fb 100644 --- a/examples/c/glr/c++-types.y +++ b/examples/c/glr/c++-types.y @@ -53,6 +53,10 @@ %code { + /* Portability issues for strdup. */ +#ifndef _XOPEN_SOURCE +# define _XOPEN_SOURCE 600 +#endif #include #include diff --git a/tests/glr-regression.at b/tests/glr-regression.at index a10f69ba..3a226f65 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -295,9 +295,7 @@ FILE *input; else { assert (strlen (buf) < sizeof buf - 1); - char *s = YY_CAST (char *, malloc (strlen (buf) + 1)); - strcpy (s, buf); - ]AT_VAL[ = s; + ]AT_VAL[ = strdup (buf); return 'V'; } break; diff --git a/tests/testsuite.h b/tests/testsuite.h index 46e99dfe..d2be5e62 100644 --- a/tests/testsuite.h +++ b/tests/testsuite.h @@ -10,3 +10,8 @@ # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" # endif #endif + +/* We use strdup, make it available. */ +#ifndef _XOPEN_SOURCE +# define _XOPEN_SOURCE 600 +#endif