aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mandocdb.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 /mandocdb.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 'mandocdb.c')
-rw-r--r--mandocdb.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/mandocdb.c b/mandocdb.c
index 86dbce2d..a2d9e494 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1,7 +1,7 @@
-/* $Id: mandocdb.c,v 1.258 2018/02/23 18:25:57 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.259 2018/08/17 20:33:37 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011-2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011-2018 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2016 Ed Maste <emaste@freebsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -185,7 +185,7 @@ static struct ohash names; /* table of all names */
static struct ohash strings; /* table of all strings */
static uint64_t name_mask;
-static const struct mdoc_handler __mdocs[MDOC_MAX - MDOC_Dd] = {
+static const struct mdoc_handler mdoc_handlers[MDOC_MAX - MDOC_Dd] = {
{ NULL, 0, NODE_NOPRT }, /* Dd */
{ NULL, 0, NODE_NOPRT }, /* Dt */
{ NULL, 0, NODE_NOPRT }, /* Os */
@@ -307,7 +307,6 @@ static const struct mdoc_handler __mdocs[MDOC_MAX - MDOC_Dd] = {
{ NULL, 0, 0 }, /* %U */
{ NULL, 0, 0 }, /* Ta */
};
-static const struct mdoc_handler *const mdocs = __mdocs - MDOC_Dd;
int
@@ -1546,25 +1545,28 @@ static void
parse_mdoc(struct mpage *mpage, const struct roff_meta *meta,
const struct roff_node *n)
{
+ const struct mdoc_handler *handler;
for (n = n->child; n != NULL; n = n->next) {
- if (n->tok == TOKEN_NONE ||
- n->tok < ROFF_MAX ||
- n->flags & mdocs[n->tok].taboo)
+ if (n->tok == TOKEN_NONE || n->tok < ROFF_MAX)
continue;
assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
+ handler = mdoc_handlers + (n->tok - MDOC_Dd);
+ if (n->flags & handler->taboo)
+ continue;
+
switch (n->type) {
case ROFFT_ELEM:
case ROFFT_BLOCK:
case ROFFT_HEAD:
case ROFFT_BODY:
case ROFFT_TAIL:
- if (mdocs[n->tok].fp != NULL &&
- (*mdocs[n->tok].fp)(mpage, meta, n) == 0)
+ if (handler->fp != NULL &&
+ (*handler->fp)(mpage, meta, n) == 0)
break;
- if (mdocs[n->tok].mask)
+ if (handler->mask)
putmdockey(mpage, n->child,
- mdocs[n->tok].mask, mdocs[n->tok].taboo);
+ handler->mask, handler->taboo);
break;
default:
continue;