Re: Bison 3.6.92 released [beta]

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.bugs
Message-ID <[email protected]>
Hi Dagobert,

> Le 19 juil. 2020 à 14:11, Dagobert Michelsen <[email protected]> a écrit :
> 
> Hi Akim,
> 
> I get a failure on both Solaris 10 Sparc and x86 with Sun Studio 12:
> 
>  GEN      doc/bison.help
> tests/bison: line 42: 19631 Abort                   (core dumped) $PREBISON "$abs_top_builddir/src/bison" ${1+"$@"} 2> "$stderr"
> Assertion failed: strlen (arg->fallback) + 1 < sizeof arg->buf, file src/glyphs.c, line 76, function on_failure
> gmake: *** [Makefile:10400: doc/bison.help] Error 134

Wow...  Thanks *a lot* for catching this.  sizeof (char*) is 8 on all
the machines I ran this beta against...

Could you please give a try to

https://www.lrde.epita.fr/~akim/private/bison/bison-3.6.92.2-d1395.tar.gz
https://www.lrde.epita.fr/~akim/private/bison/bison-3.6.92.2-d1395.tar.lz
https://www.lrde.epita.fr/~akim/private/bison/bison-3.6.92.2-d1395.tar.xz

which includes the appended patch?  Thanks in advance.

commit d1395aff04b1f7b8d8219402f705e11764c55551
Author: Akim Demaille <[email protected]>
Date:   Sun Jul 19 16:05:15 2020 +0200

    glyphs: fix types
    
    The code was written on top of buffers of `char[26]`, and then was
    changed to use `char *`, yet was still using `sizeof buf`, which
    became `sizeof (char *)` instead of `sizeof (char[26])`.
    
    Reported by Dagobert Michelsen.
    https://lists.gnu.org/r/bug-bison/2020-07/msg00023.html
    
    * src/glyphs.h, src/glyphs.c: Get rid of uses of `char *`, use only
    glyph_buffer_t.

diff --git a/src/glyphs.c b/src/glyphs.c
index b69659d8..dcd7f0c7 100644
--- a/src/glyphs.c
+++ b/src/glyphs.c
@@ -28,24 +28,17 @@
 #include <mbswidth.h>
 #include <unicodeio.h>
 
-// In gnulib/lib/unicodeio.h unicode_to_mb uses a buffer of 25 bytes.
-typedef char glyph_buffer_t[26];
 
-
-static glyph_buffer_t arrow_buf;
-const char *arrow;
+glyph_buffer_t arrow;
 int arrow_width;
 
-static glyph_buffer_t down_arrow_buf;
-const char *down_arrow;
+glyph_buffer_t down_arrow;
 int down_arrow_width;
 
-static glyph_buffer_t dot_buf;
-const char *dot;
+glyph_buffer_t dot;
 int dot_width;
 
-static glyph_buffer_t empty_buf;
-const char *empty;
+glyph_buffer_t empty;
 int empty_width;
 
 const char *derivation_separator = " ";
@@ -53,8 +46,7 @@ int derivation_separator_width = 1;
 
 typedef struct
 {
-  const char **glyph;
-  char *buf;
+  glyph_buffer_t *pbuf;
   const char *fallback;
 } callback_arg_t;
 
@@ -63,8 +55,8 @@ static long
 on_success (const char *buf, size_t buflen, void *callback_arg)
 {
   callback_arg_t *arg = (callback_arg_t *) callback_arg;
-  assert (buflen + 1 < sizeof arg->buf);
-  *stpncpy (arg->buf, buf, buflen) = '\0';
+  assert (buflen + 1 < sizeof *arg->pbuf);
+  *stpncpy (*arg->pbuf, buf, buflen) = '\0';
   return 1;
 }
 
@@ -73,19 +65,17 @@ on_failure (unsigned code MAYBE_UNUSED, const char *msg MAYBE_UNUSED,
             void *callback_arg)
 {
   callback_arg_t *arg = (callback_arg_t *) callback_arg;
-  assert (strlen (arg->fallback) + 1 < sizeof arg->buf);
-  strcpy (arg->buf, arg->fallback);
+  assert (strlen (arg->fallback) + 1 < sizeof *arg->pbuf);
+  strcpy (*arg->pbuf, arg->fallback);
   return 0;
 }
 
 static bool
-glyph_set (const char **glyph,
-           char buf[26], int *width,
+glyph_set (glyph_buffer_t *glyph, int *width,
            unsigned code, const char *fallback)
 {
-  callback_arg_t arg = { glyph, buf, fallback };
+  callback_arg_t arg = { glyph, fallback };
   int res = unicode_to_mb (code, on_success, on_failure, &arg);
-  *glyph = buf;
   *width = mbswidth (*glyph, 0);
   return res;
 }
@@ -93,11 +83,11 @@ glyph_set (const char **glyph,
 void
 glyphs_init (void)
 {
-  glyph_set (&arrow,      arrow_buf,      &arrow_width,      0x2192, "->");
-  glyph_set (&dot,        dot_buf,        &dot_width,        0x2022, ".");
-  glyph_set (&down_arrow, down_arrow_buf, &down_arrow_width, 0x21b3, "`->");
-  glyph_set (&empty,      empty_buf,      &empty_width,      0x03b5, "%empty");
+  glyph_set (&arrow,      &arrow_width,      0x2192, "->");
+  glyph_set (&dot,        &dot_width,        0x2022, ".");
+  glyph_set (&down_arrow, &down_arrow_width, 0x21b3, "`->");
+  glyph_set (&empty,      &empty_width,      0x03b5, "%empty");
 
-  strncat (down_arrow_buf, " ", sizeof down_arrow_buf - strlen (down_arrow_buf) - 1);
+  strncat (down_arrow, " ", sizeof down_arrow - strlen (down_arrow) - 1);
   down_arrow_width += 1;
 }
diff --git a/src/glyphs.h b/src/glyphs.h
index 43f0a155..0af7e23c 100644
--- a/src/glyphs.h
+++ b/src/glyphs.h
@@ -23,20 +23,24 @@
 /* Initialize the following variables.  */
 void glyphs_init (void);
 
+/* In gnulib/lib/unicodeio.h unicode_to_mb uses a buffer of 25 bytes.
+   In down_arrow, we append one space.  */
+typedef char glyph_buffer_t[26];
+
 /* "→", separates the lhs of a rule from its rhs.  */
-extern const char *arrow;
+extern glyph_buffer_t arrow;
 extern int arrow_width;
 
 /* "•", a point in an item (aka, a dotted rule).  */
-extern const char *dot;
+extern glyph_buffer_t dot;
 extern int dot_width;
 
 /* "↳ ", below an lhs to announce the rhs.  */
-extern const char *down_arrow;
+extern glyph_buffer_t down_arrow;
 extern int down_arrow_width;
 
 /* "ε", an empty rhs.  */
-extern const char *empty;
+extern glyph_buffer_t empty;
 extern int empty_width;
 
 /* " ", separate symbols in the rhs of a derivation.  */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.