summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-01-31 00:12:41 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-01-31 00:12:41 +0000
commit3b15b25a7deff6f634e8233f6f8d96485308c592 (patch)
tree3db8a0db30d9044a660aacd29afe763a45f05d64
parent36097423ac8b35b42f700e0b63e3b6ac44d88235 (diff)
downloadmandoc-3b15b25a7deff6f634e8233f6f8d96485308c592.tar.gz
Use relative offsets instead of absolute pointers for the terminal
font stack. The latter fail after the stack is grown with realloc(). Fixing an assertion failure found by jsg@ with afl some time ago (test case number 51).
-rw-r--r--mdoc.h2
-rw-r--r--mdoc_term.c2
-rw-r--r--tbl_term.c4
-rw-r--r--term.c20
-rw-r--r--term.h3
5 files changed, 11 insertions, 20 deletions
diff --git a/mdoc.h b/mdoc.h
index 3d48e99b..33ec903b 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -366,7 +366,7 @@ struct mdoc_node {
enum mdoc_type type; /* AST node type */
enum mdoc_sec sec; /* current named section */
union mdoc_data *norm; /* normalised args */
- const void *prev_font; /* before entering this node */
+ int prev_font; /* before entering this node */
/* FIXME: these can be union'd to shave a few bytes. */
struct mdoc_arg *args; /* BLOCK/ELEM */
struct mdoc_node *pending; /* BLOCK */
diff --git a/mdoc_term.c b/mdoc_term.c
index 2b6a8c73..64e86d48 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -307,7 +307,7 @@ print_mdoc_node(DECL_ARGS)
chld = 1;
offset = p->offset;
rmargin = p->rmargin;
- n->prev_font = term_fontq(p);
+ n->prev_font = p->fonti;
memset(&npair, 0, sizeof(struct termpair));
npair.ppair = pair;
diff --git a/tbl_term.c b/tbl_term.c
index b96804c9..f4206405 100644
--- a/tbl_term.c
+++ b/tbl_term.c
@@ -414,9 +414,9 @@ tbl_number(struct termp *tp, const struct tbl_opts *opts,
static void
tbl_word(struct termp *tp, const struct tbl_dat *dp)
{
- const void *prev_font;
+ int prev_font;
- prev_font = term_fontq(tp);
+ prev_font = tp->fonti;
if (dp->layout->flags & TBL_CELL_BOLD)
term_fontpush(tp, TERMFONT_BOLD);
else if (dp->layout->flags & TBL_CELL_ITALIC)
diff --git a/term.c b/term.c
index 1887a6c4..b32fd1f1 100644
--- a/term.c
+++ b/term.c
@@ -363,22 +363,14 @@ term_fontpush(struct termp *p, enum termfont f)
p->fontq[p->fonti] = f;
}
-/* Retrieve pointer to current font. */
-const enum termfont *
-term_fontq(struct termp *p)
-{
-
- return(&p->fontq[p->fonti]);
-}
-
/* Flush to make the saved pointer current again. */
void
-term_fontpopq(struct termp *p, const enum termfont *key)
+term_fontpopq(struct termp *p, int i)
{
- while (p->fonti >= 0 && key < p->fontq + p->fonti)
- p->fonti--;
- assert(p->fonti >= 0);
+ assert(i >= 0);
+ if (p->fonti > i)
+ p->fonti = i;
}
/* Pop one font off the stack. */
@@ -568,7 +560,7 @@ encode1(struct termp *p, int c)
if (p->col + 6 >= p->maxcols)
adjbuf(p, p->col + 6);
- f = *term_fontq(p);
+ f = p->fontq[p->fonti];
if (TERMFONT_UNDER == f || TERMFONT_BI == f) {
p->buf[p->col++] = '_';
@@ -600,7 +592,7 @@ encode(struct termp *p, const char *word, size_t sz)
* character by character.
*/
- if (*term_fontq(p) == TERMFONT_NONE) {
+ if (p->fontq[p->fonti] == TERMFONT_NONE) {
if (p->col + sz >= p->maxcols)
adjbuf(p, p->col + sz);
for (i = 0; i < sz; i++)
diff --git a/term.h b/term.h
index f9170f0c..351b2ee0 100644
--- a/term.h
+++ b/term.h
@@ -126,10 +126,9 @@ int term_vspan(const struct termp *, const struct roffsu *);
size_t term_strlen(const struct termp *, const char *);
size_t term_len(const struct termp *, size_t);
-const enum termfont *term_fontq(struct termp *);
void term_fontpush(struct termp *, enum termfont);
void term_fontpop(struct termp *);
-void term_fontpopq(struct termp *, const enum termfont *);
+void term_fontpopq(struct termp *, int);
void term_fontrepl(struct termp *, enum termfont);
void term_fontlast(struct termp *);