summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2020-05-04 06:37:59 +0200
committerAkim Demaille <akim.demaille@gmail.com>2020-05-04 06:48:00 +0200
commitce27796b7473d8649f0237a7506385e759a2ba99 (patch)
tree106891156aa1336609d6ffa8eba10fd6a6a8a95e /examples
parent6135fdc15236947defa87db66e92b25559ee387d (diff)
downloadbison-ce27796b7473d8649f0237a7506385e759a2ba99.tar.gz
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...
Diffstat (limited to 'examples')
-rw-r--r--examples/c/bistromathic/parse.y4
1 files changed, 3 insertions, 1 deletions
diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y
index 8db9d457..38fedb46 100644
--- a/examples/c/bistromathic/parse.y
+++ b/examples/c/bistromathic/parse.y
@@ -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';