summaryrefslogtreecommitdiffstats
path: root/roff.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-08-01 15:08:46 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-08-01 15:08:46 +0000
commit120073f11aa98a6e6187a5bd14df4505cfe2c087 (patch)
tree96aeb69bef21aad0d825b912702dbaebd16ea269 /roff.c
parent1004133003f9d9a7e7783789c69eeb59bba73d1b (diff)
downloadmandoc-120073f11aa98a6e6187a5bd14df4505cfe2c087.tar.gz
Dynamically allocate the stack of roff(7) .ie condition values
and thus get rid of the last useless fatal error.
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/roff.c b/roff.c
index fe26c1fe..bf7b9e88 100644
--- a/roff.c
+++ b/roff.c
@@ -106,11 +106,8 @@ struct roffreg {
struct roff {
struct mparse *parse; /* parse point */
- int options; /* parse options */
struct roffnode *last; /* leaf of stack */
- int rstack[RSTACK_MAX]; /* stack of !`ie' rules */
- char control; /* control character */
- int rstackpos; /* position in rstack */
+ int *rstack; /* stack of inverted `ie' values */
struct roffreg *regtab; /* number registers */
struct roffkv *strtab; /* user-defined strings & macros */
struct roffkv *xmbtab; /* multi-byte trans table (`tr') */
@@ -122,6 +119,10 @@ struct roff {
struct eqn_node *last_eqn; /* last equation parsed */
struct eqn_node *first_eqn; /* first equation parsed */
struct eqn_node *eqn; /* current equation being parsed */
+ int options; /* parse options */
+ int rstacksz; /* current size limit of rstack */
+ int rstackpos; /* position in rstack */
+ char control; /* control character */
};
struct roffnode {
@@ -420,32 +421,32 @@ roff_free1(struct roff *r)
r->first_tbl = tbl->next;
tbl_free(tbl);
}
-
r->first_tbl = r->last_tbl = r->tbl = NULL;
while (NULL != (e = r->first_eqn)) {
r->first_eqn = e->next;
eqn_free(e);
}
-
r->first_eqn = r->last_eqn = r->eqn = NULL;
while (r->last)
roffnode_pop(r);
- roff_freestr(r->strtab);
- roff_freestr(r->xmbtab);
-
- r->strtab = r->xmbtab = NULL;
+ free (r->rstack);
+ r->rstack = NULL;
+ r->rstacksz = 0;
+ r->rstackpos = -1;
roff_freereg(r->regtab);
-
r->regtab = NULL;
+ roff_freestr(r->strtab);
+ roff_freestr(r->xmbtab);
+ r->strtab = r->xmbtab = NULL;
+
if (r->xtab)
for (i = 0; i < 128; i++)
free(r->xtab[i].p);
-
free(r->xtab);
r->xtab = NULL;
}
@@ -1283,10 +1284,10 @@ roff_cond(ROFF_ARGS)
*/
if (ROFF_ie == tok) {
- if (r->rstackpos == RSTACK_MAX - 1) {
- mandoc_msg(MANDOCERR_MEM,
- r->parse, ln, ppos, NULL);
- return(ROFF_ERR);
+ if (r->rstackpos + 1 == r->rstacksz) {
+ r->rstacksz += 16;
+ r->rstack = mandoc_reallocarray(r->rstack,
+ r->rstacksz, sizeof(int));
}
r->rstack[++r->rstackpos] = !r->last->rule;
}