[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [platform-testers] Bison 3.5.91
From: |
Akim Demaille |
Subject: |
Re: [platform-testers] Bison 3.5.91 |
Date: |
Sun, 3 May 2020 17:04:01 +0200 |
Hi Dagobert!
> Le 3 mai 2020 à 13:52, Dagobert Michelsen <address@hidden> a écrit :
>
> Hi Akim,
>
> Am 03.05.2020 um 13:19 schrieb Akim Demaille <address@hidden>:
>> Here are the compressed sources:
>> https://alpha.gnu.org/gnu/bison/bison-3.5.92.tar.gz (5.1MB)
>> https://alpha.gnu.org/gnu/bison/bison-3.5.92.tar.xz (3.1MB)
>
> I have a linker error on missing strndup on Solaris 10 Sparc:
>
> CCLD examples/c/bistromathic/bistromathic
> Undefined first referenced
> symbol in file
> strndup
> examples/c/bistromathic/bistromathic-parse.o
Thanks a lot! I'm installing this.
commit 2caea8d08be1a29f2aafd56c3062c46153579f97
Author: Akim Demaille <address@hidden>
Date: Sun May 3 17:00:41 2020 +0200
bistromathic: beware of portability issues with strndup
Reported by Dagobert Michelsen.
https://lists.gnu.org/r/bug-bison/2020-05/msg00026.html
* examples/c/bistromathic/parse.y (xstrndup): New.
Use it.
diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y
index 479d1bf4..292057b8 100644
--- a/examples/c/bistromathic/parse.y
+++ b/examples/c/bistromathic/parse.y
@@ -1,6 +1,7 @@
%require "3.6"
%code top {
+ #include <assert.h>
#include <ctype.h> // isdigit
#include <locale.h> // LC_ALL
#include <math.h> // cos, sin, etc.
@@ -316,7 +317,7 @@ error_format_string (int argc)
{
switch (argc)
{
- default: /* Avoid compiler warnings. */
+ default: // Avoid compiler warnings.
case 0: return _("%@: syntax error");
case 1: return _("%@: syntax error: unexpected %u");
// TRANSLATORS: '%@' is a location in a file, '%u' is an
@@ -393,6 +394,20 @@ void yyerror (YYLTYPE *loc, char const *format, ...)
}
+// Return a newly allocated copy of at most N bytes of STRING. In
+// other words, return a copy of the initial segment of length N of
+// STRING.
+static char *
+xstrndup (const char *string, size_t n)
+{
+ size_t len = strnlen (s, n);
+ char *new = malloc (len + 1);
+ assert (new);
+ new[len] = '\0';
+ return memcpy (new, s, len);
+}
+
+
/*-----------.
| Readline. |
`-----------*/
@@ -438,11 +453,11 @@ expected_tokens (const char *input,
return res;
}
-/* Attempt to complete on the contents of TEXT. START and END bound the
- region of rl_line_buffer that contains the word to complete. TEXT is
- the word to complete. We can use the entire contents of rl_line_buffer
- in case we want to do some simple parsing. Return the array of matches,
- or NULL if there aren't any. */
+// Attempt to complete on the contents of TEXT. START and END bound
+// the region of rl_line_buffer that contains the word to complete.
+// TEXT is the word to complete. We can use the entire contents of
+// rl_line_buffer in case we want to do some simple parsing. Return
+// the array of matches, or NULL if there aren't any.
char **
completion (const char *text, int start, int end)
{
@@ -453,7 +468,7 @@ completion (const char *text, int start, int end)
// Get list of token numbers.
int tokens[YYNTOKENS];
- char *line = strndup (rl_line_buffer, start);
+ char *line = xstrndup (rl_line_buffer, start);
int ntokens = expected_tokens (line, tokens, YYNTOKENS);
free (line);
@@ -495,7 +510,7 @@ completion (const char *text, int start, int end)
for (int j = 0; j < lcplen; ++j)
if (matches[1][j] != matches[i][j])
lcplen = j;
- matches[0] = strndup (matches[1], lcplen);
+ matches[0] = xstrndup (matches[1], lcplen);
}
if (yydebug)