aboutsummaryrefslogtreecommitdiffstatshomepage
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
commitde2a1122a661dd4bd4004854891d44e87d63c6c2 (patch)
tree79380a193e1374fd7e4b697152b0b7aea304ddf8 /mdoc_man.c
parent3f485a7ff74c3707363ed47362ccc8a7855b0f58 (diff)
downloadmandoc-de2a1122a661dd4bd4004854891d44e87d63c6c2.tar.gz
mandoc-de2a1122a661dd4bd4004854891d44e87d63c6c2.tar.zst
mandoc-de2a1122a661dd4bd4004854891d44e87d63c6c2.zip
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.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/mdoc_man.c b/mdoc_man.c
index bcf9207f..17711700 100644
--- a/mdoc_man.c
+++ b/mdoc_man.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_man.c,v 1.126 2018/04/11 17:11:13 schwarze Exp $ */
+/* $Id: mdoc_man.c,v 1.127 2018/08/17 20:33:37 schwarze Exp $ */
/*
* Copyright (c) 2011-2018 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -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;