From de2a1122a661dd4bd4004854891d44e87d63c6c2 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Fri, 17 Aug 2018 20:33:37 +0000 Subject: Remove more pointer arithmetic passing via regions outside the array that is undefined according to the C standard. Robert Elz pointed out i wasn't quite done yet. --- mandocdb.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'mandocdb.c') 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 - * Copyright (c) 2011-2017 Ingo Schwarze + * Copyright (c) 2011-2018 Ingo Schwarze * Copyright (c) 2016 Ed Maste * * 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; -- cgit v1.2.3-56-ge451