aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_validate.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2016-01-08 17:48:09 +0000
committerIngo Schwarze <schwarze@openbsd.org>2016-01-08 17:48:09 +0000
commit924c4755ac64b780903344b188653f513990a771 (patch)
tree8790707d642423006b0f909baf400a6dc333adcb /mdoc_validate.c
parentc2d0e548871bfed103ed040312a4333026ee10f1 (diff)
downloadmandoc-924c4755ac64b780903344b188653f513990a771.tar.gz
mandoc-924c4755ac64b780903344b188653f513990a771.tar.zst
mandoc-924c4755ac64b780903344b188653f513990a771.zip
Delete the redundant "nchild" member of struct roff_node, replacing
most uses by one, a few by two pointer checks, and only one by a tiny loop - not only making data smaller, but code shorter as well. This gets rid of an implicit invariant that confused both static analysis tools and human auditors. No functional change.
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r--mdoc_validate.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 9261e2fb..e369349c 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,7 +1,7 @@
-/* $Id: mdoc_validate.c,v 1.300 2015/10/30 19:04:16 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.301 2016/01/08 17:48:09 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2016 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -1278,7 +1278,8 @@ post_bl_head(POST_ARGS)
argv = nbl->args->argv + j;
i = argv->sz;
- argv->sz += nh->nchild;
+ for (nch = nh->child; nch != NULL; nch = nch->next)
+ argv->sz++;
argv->value = mandoc_reallocarray(argv->value,
argv->sz, sizeof(char *));
@@ -1291,7 +1292,6 @@ post_bl_head(POST_ARGS)
nnext = nch->next;
roff_node_delete(NULL, nch);
}
- nh->nchild = 0;
nh->child = NULL;
}
@@ -1352,14 +1352,11 @@ post_bl(POST_ARGS)
*/
assert(nchild->prev == NULL);
- if (--nbody->nchild == 0) {
- nbody->child = NULL;
+ nbody->child = nnext;
+ if (nnext == NULL)
nbody->last = NULL;
- assert(nnext == NULL);
- } else {
- nbody->child = nnext;
+ else
nnext->prev = NULL;
- }
/*
* Relink this child.
@@ -1370,7 +1367,6 @@ post_bl(POST_ARGS)
nchild->next = nblock;
nblock->prev = nchild;
- nparent->nchild++;
if (nprev == NULL)
nparent->child = nchild;
else
@@ -1688,7 +1684,9 @@ post_sh_see_also(POST_ARGS)
n = mdoc->last->child;
lastname = lastsec = lastpunct = NULL;
while (n != NULL) {
- if (n->tok != MDOC_Xr || n->nchild < 2)
+ if (n->tok != MDOC_Xr ||
+ n->child == NULL ||
+ n->child->next == NULL)
break;
/* Process one .Xr node. */
@@ -1744,7 +1742,7 @@ child_an(const struct roff_node *n)
{
for (n = n->child; n != NULL; n = n->next)
- if ((n->tok == MDOC_An && n->nchild) || child_an(n))
+ if ((n->tok == MDOC_An && n->child != NULL) || child_an(n))
return 1;
return 0;
}
@@ -1931,7 +1929,7 @@ post_par(POST_ARGS)
post_prevpar(mdoc);
if (np->tok == MDOC_sp) {
- if (np->nchild > 1)
+ if (np->child != NULL && np->child->next != NULL)
mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
np->child->next->line, np->child->next->pos,
"sp ... %s", np->child->next->string);