mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
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.
This commit is contained in:
4
NEWS
4
NEWS
@@ -2,6 +2,10 @@ GNU Bison NEWS
|
||||
|
||||
* Noteworthy changes in release ?.? (????-??-??) [?]
|
||||
|
||||
** Bug fixes
|
||||
|
||||
Portability issues.
|
||||
|
||||
|
||||
* Noteworthy changes in release 3.6.92 (2020-07-19) [beta]
|
||||
|
||||
|
||||
42
src/glyphs.c
42
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;
|
||||
}
|
||||
|
||||
12
src/glyphs.h
12
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. */
|
||||
|
||||
Reference in New Issue
Block a user