mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
examples: beware of strnlen portability issues
One function missing on Solaris 10 Sparc:
CCLD examples/c/bistromathic/bistromathic
Undefined first referenced
symbol in file
strnlen examples/c/bistromathic/bistromathic-parse.o
ld: fatal: symbol referencing errors. No output written to examples/c/bistromathic/bistromathic
Reported by Dagobert Michelsen.
https://lists.gnu.org/r/bug-bison/2020-05/msg00048.html
* examples/c/bistromathic/parse.y (xstrndup): Don't use strnlen.
xstrndup is assembled from gnulib's xstrndup, strndup and strnlen...
This commit is contained in:
@@ -400,7 +400,9 @@ void yyerror (YYLTYPE *loc, char const *format, ...)
|
||||
static char *
|
||||
xstrndup (const char *string, size_t n)
|
||||
{
|
||||
size_t len = strnlen (string, n);
|
||||
// len = strnlen (string, n), portably.
|
||||
const char *end = memchr (string, '\0', n);
|
||||
size_t len = end ? (size_t) (end - string) : n;
|
||||
char *new = malloc (len + 1);
|
||||
assert (new);
|
||||
new[len] = '\0';
|
||||
|
||||
Reference in New Issue
Block a user