diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2015-01-31 00:12:41 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2015-01-31 00:12:41 +0000 |
commit | 3b15b25a7deff6f634e8233f6f8d96485308c592 (patch) | |
tree | 3db8a0db30d9044a660aacd29afe763a45f05d64 /term.c | |
parent | 36097423ac8b35b42f700e0b63e3b6ac44d88235 (diff) | |
download | mandoc-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).
Diffstat (limited to 'term.c')
-rw-r--r-- | term.c | 20 |
1 files changed, 6 insertions, 14 deletions
@@ -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++) |