summaryrefslogtreecommitdiffstats
path: root/mdoc_man.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-08-17 20:33:37 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-08-17 20:33:37 +0000
commita55868d2cb7c07237689f307d3a55b33b257de09 (patch)
tree6e622b38423ae091b6a8a02b0843ea2bfb7958b4 /mdoc_man.c
parentf6077aba4f0b9ece3ceff820c0c651d148df1a37 (diff)
downloadmandoc-a55868d2cb7c07237689f307d3a55b33b257de09.tar.gz
Remove more pointer arithmetic passing via regions outside the array
that is undefined according to the C standard. Robert Elz <kre at munnari dot oz dot au> pointed out i wasn't quite done yet.
Diffstat (limited to 'mdoc_man.c')
-rw-r--r--mdoc_man.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/mdoc_man.c b/mdoc_man.c
index 2b7660dd..a7a85df2 100644
--- a/mdoc_man.c
+++ b/mdoc_man.c
@@ -36,7 +36,7 @@
typedef int (*int_fp)(DECL_ARGS);
typedef void (*void_fp)(DECL_ARGS);
-struct manact {
+struct mdoc_man_act {
int_fp cond; /* DON'T run actions */
int_fp pre; /* pre-node action */
void_fp post; /* post-node action */
@@ -124,7 +124,7 @@ static void print_width(const struct mdoc_bl *,
static void print_count(int *);
static void print_node(DECL_ARGS);
-static const void_fp roff_manacts[ROFF_MAX] = {
+static const void_fp roff_man_acts[ROFF_MAX] = {
pre_br, /* br */
pre_onearg, /* ce */
pre_ft, /* ft */
@@ -137,7 +137,7 @@ static const void_fp roff_manacts[ROFF_MAX] = {
pre_onearg, /* ti */
};
-static const struct manact __manacts[MDOC_MAX - MDOC_Dd] = {
+static const struct mdoc_man_act mdoc_man_acts[MDOC_MAX - MDOC_Dd] = {
{ NULL, NULL, NULL, NULL, NULL }, /* Dd */
{ NULL, NULL, NULL, NULL, NULL }, /* Dt */
{ NULL, NULL, NULL, NULL, NULL }, /* Os */
@@ -259,7 +259,7 @@ static const struct manact __manacts[MDOC_MAX - MDOC_Dd] = {
{ NULL, NULL, post_percent, NULL, NULL }, /* %U */
{ NULL, NULL, NULL, NULL, NULL }, /* Ta */
};
-static const struct manact *const manacts = __manacts - MDOC_Dd;
+static const struct mdoc_man_act *mdoc_man_act(enum roff_tok);
static int outflags;
#define MMAN_spc (1 << 0) /* blank character before next word */
@@ -290,6 +290,13 @@ static struct {
} fontqueue;
+static const struct mdoc_man_act *
+mdoc_man_act(enum roff_tok tok)
+{
+ assert(tok >= MDOC_Dd && tok <= MDOC_MAX);
+ return mdoc_man_acts + (tok - MDOC_Dd);
+}
+
static int
man_strlen(const char *cp)
{
@@ -640,9 +647,9 @@ man_mdoc(void *arg, const struct roff_man *mdoc)
static void
print_node(DECL_ARGS)
{
- const struct manact *act;
- struct roff_node *sub;
- int cond, do_sub;
+ const struct mdoc_man_act *act;
+ struct roff_node *sub;
+ int cond, do_sub;
if (n->flags & NODE_NOPRT)
return;
@@ -680,15 +687,14 @@ print_node(DECL_ARGS)
else if (outflags & MMAN_Sm)
outflags |= MMAN_spc;
} else if (n->tok < ROFF_MAX) {
- (*roff_manacts[n->tok])(meta, n);
+ (*roff_man_acts[n->tok])(meta, n);
return;
} else {
- assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
/*
* Conditionally run the pre-node action handler for a
* node.
*/
- act = manacts + n->tok;
+ act = mdoc_man_act(n->tok);
cond = act->cond == NULL || (*act->cond)(meta, n);
if (cond && act->pre != NULL &&
(n->end == ENDBODY_NOT || n->child != NULL))
@@ -736,7 +742,7 @@ pre_enc(DECL_ARGS)
{
const char *prefix;
- prefix = manacts[n->tok].prefix;
+ prefix = mdoc_man_act(n->tok)->prefix;
if (NULL == prefix)
return 1;
print_word(prefix);
@@ -749,7 +755,7 @@ post_enc(DECL_ARGS)
{
const char *suffix;
- suffix = manacts[n->tok].suffix;
+ suffix = mdoc_man_act(n->tok)->suffix;
if (NULL == suffix)
return;
outflags &= ~(MMAN_spc | MMAN_nl);
@@ -774,7 +780,7 @@ static void
post_percent(DECL_ARGS)
{
- if (pre_em == manacts[n->tok].pre)
+ if (mdoc_man_act(n->tok)->pre == pre_em)
font_pop();
if (n->next) {
print_word(",");
@@ -820,7 +826,7 @@ pre_sect(DECL_ARGS)
if (n->type == ROFFT_HEAD) {
outflags |= MMAN_sp;
- print_block(manacts[n->tok].prefix, 0);
+ print_block(mdoc_man_act(n->tok)->prefix, 0);
print_word("");
putchar('\"');
outflags &= ~MMAN_spc;