diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2019-11-09 14:39:49 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2019-11-09 14:39:49 +0000 |
commit | 156b76737c1c71b31afaca9b589a8636adca8d05 (patch) | |
tree | 8c9f889565d440cdc278114eb1a5012acb6e7dd8 /roff.c | |
parent | 625e2eb1b35f1dfdffd4fba3c45ce820e5c8c863 (diff) | |
download | mandoc-156b76737c1c71b31afaca9b589a8636adca8d05.tar.gz mandoc-156b76737c1c71b31afaca9b589a8636adca8d05.tar.zst mandoc-156b76737c1c71b31afaca9b589a8636adca8d05.zip |
In the past, generating comment nodes stopped at the .TH or .Dd
macro, which is usually close to the beginning of the file, right
after the Copyright header comments. But espie@ found horrible
input files in the textproc/fstrcmp port that generate lots of parse
nodes before even getting to the header macro. In some formatters,
comment nodes after some kinds of real content triggered assertions.
So make sure generation of comment nodes stops once real content is
encountered.
Diffstat (limited to 'roff.c')
-rw-r--r-- | roff.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.366 2019/07/01 22:56:24 schwarze Exp $ */ +/* $Id: roff.c,v 1.367 2019/11/09 14:39:49 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015, 2017-2019 Ingo Schwarze <schwarze@openbsd.org> @@ -771,6 +771,7 @@ void roff_reset(struct roff *r) { roff_free1(r); + r->options |= MPARSE_COMMENT; r->format = r->options & (MPARSE_MDOC | MPARSE_MAN); r->control = '\0'; r->escape = '\\'; @@ -800,7 +801,7 @@ roff_alloc(int options) r = mandoc_calloc(1, sizeof(struct roff)); r->reqtab = roffhash_alloc(0, ROFF_RENAMED); - r->options = options; + r->options = options | MPARSE_COMMENT; r->format = options & (MPARSE_MDOC | MPARSE_MAN); r->mstackpos = -1; r->rstackpos = -1; @@ -1246,7 +1247,7 @@ roff_expand(struct roff *r, struct buf *buf, int ln, int pos, char newesc) * in the syntax tree. */ - if (newesc != ASCII_ESC && r->format == 0) { + if (newesc != ASCII_ESC && r->options & MPARSE_COMMENT) { while (*ep == ' ' || *ep == '\t') ep--; ep[1] = '\0'; @@ -1815,8 +1816,10 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs) roff_addtbl(r->man, ln, r->tbl); return e; } - if ( ! ctl) + if ( ! ctl) { + r->options &= ~MPARSE_COMMENT; return roff_parsetext(r, buf, pos, offs) | e; + } /* Skip empty request lines. */ @@ -1839,6 +1842,7 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs) /* No scope is open. This is a new request or macro. */ + r->options &= ~MPARSE_COMMENT; spos = pos; t = roff_parse(r, buf->buf, &pos, ln, ppos); |