From dfd27e6cd9c8f1f55ef0e659bcb6dd71d22a1057 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sun, 30 Aug 2015 21:10:56 +0000 Subject: Drop leading, internal, and trailing blank characters in \o (overstrike) escape sequences; that's cleaner for all output modes, and it's required to prevent the PostScript/PDF formatter from dying on assertions. Bug found by jsg@ with afl. --- term.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'term.c') diff --git a/term.c b/term.c index 0bd147cc..acda12f7 100644 --- a/term.c +++ b/term.c @@ -499,6 +499,9 @@ term_word(struct termp *p, const char *word) p->flags |= TERMP_BACKBEFORE; } } + /* Trim trailing backspace/blank pair. */ + if (p->col > 2 && p->buf[p->col - 1] == ' ') + p->col -= 2; continue; default: continue; @@ -561,7 +564,10 @@ encode1(struct termp *p, int c) p->fontq[p->fonti] : TERMFONT_NONE; if (p->flags & TERMP_BACKBEFORE) { - p->buf[p->col++] = 8; + if (p->buf[p->col - 1] == ' ') + p->col--; + else + p->buf[p->col++] = 8; p->flags &= ~TERMP_BACKBEFORE; } if (TERMFONT_UNDER == f || TERMFONT_BI == f) { -- cgit