diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-11-21 01:52:46 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-11-21 01:52:46 +0000 |
commit | f9c5aa7d69d88925112dd90b779add4bc63ba3df (patch) | |
tree | a5920212e1a96269a7d30be129b4bff01199a9bd | |
parent | 422a96a9ad6a4ffd61a706d7847f96526bfdcdd3 (diff) |
We repeatedly observed assertion crashes in the low-level terminal
output handler because the high level terminal formatters could be
tricked into setting the left margin further to the right than the
right margin. Today, jsg@ found more of these with afl.
Change the internal interface between both levels, aiming for
simplicity and robustness of the code. Treat both margins as
*independent* settings: Now, termp.offset is the requested left
margin, and termp.rmargin is the available space. Let the lower
level cope with that case of insufficient space.
Obviously, high level code that does centering or flush right
still has to do careful checks, so i did a full audit of margin
settings in the terminal formatters.
Fixes crashes caused by excessively long title or date strings in
the man(7) footer, operating system or date strings in the mdoc(7)
footer, volume strings in the man(7) or mdoc(7) header, and a few
cases related to some non-prologue macros.
26 files changed, 190 insertions, 59 deletions
diff --git a/regress/usr.bin/mandoc/man/HP/spacing.in b/regress/usr.bin/mandoc/man/HP/spacing.in index 550b27fe3d5..5a9614f1b01 100644 --- a/regress/usr.bin/mandoc/man/HP/spacing.in +++ b/regress/usr.bin/mandoc/man/HP/spacing.in @@ -1,4 +1,4 @@ -.TH HP-SPACING 1 "February 5, 2011" OpenBSD +.TH HP-SPACING 1 "November 20, 2014" OpenBSD .SH NAME HP-spacing \- spacing in hanged lists .SH DESCRIPTION @@ -21,5 +21,8 @@ Indented text. .HP a much longer tag Indented text. +.HP 78n +Testing a hanged paragraph with a large indentation width, +in this case 78n, requires more text. .LP Normal text. diff --git a/regress/usr.bin/mandoc/man/HP/spacing.out_ascii b/regress/usr.bin/mandoc/man/HP/spacing.out_ascii index 04d3e8dbf4a..d4f50d42b54 100644 --- a/regress/usr.bin/mandoc/man/HP/spacing.out_ascii +++ b/regress/usr.bin/mandoc/man/HP/spacing.out_ascii @@ -20,8 +20,14 @@ DDEESSCCRRIIPPTTIIOONN a much longer tag Indented text. + Testing a hanged paragraph with a large indentation width, in this case + 78n, + requires + more + text. + Normal text. -OpenBSD February 5, 2011 HP-SPACING(1) +OpenBSD November 20, 2014 HP-SPACING(1) diff --git a/regress/usr.bin/mandoc/man/TH/Makefile b/regress/usr.bin/mandoc/man/TH/Makefile index 1ce2028eb8a..3079a99cd72 100644 --- a/regress/usr.bin/mandoc/man/TH/Makefile +++ b/regress/usr.bin/mandoc/man/TH/Makefile @@ -1,13 +1,13 @@ -# $OpenBSD: Makefile,v 1.7 2014/08/14 02:00:52 schwarze Exp $ +# $OpenBSD: Makefile,v 1.8 2014/11/21 01:52:45 schwarze Exp $ -REGRESS_TARGETS = noTH noarg onearg twoargs sixargs case -REGRESS_TARGETS += emptydate onlyyear isodate mdocdate baddate +REGRESS_TARGETS = noTH noarg onearg twoargs sixargs case longtit longvol +REGRESS_TARGETS += emptydate onlyyear isodate mdocdate baddate longdate REGRESS_TARGETS += nobody LINT_TARGETS = noTH noarg onearg twoargs case -LINT_TARGETS += emptydate baddate nobody +LINT_TARGETS += emptydate baddate longdate nobody -SKIP_GROFF = noTH -SKIP_ASCII = noTH +SKIP_GROFF = noTH longtit longvol longdate +SKIP_ASCII = noTH .include <bsd.regress.mk> diff --git a/regress/usr.bin/mandoc/man/TH/longdate.in b/regress/usr.bin/mandoc/man/TH/longdate.in new file mode 100644 index 00000000000..263df782156 --- /dev/null +++ b/regress/usr.bin/mandoc/man/TH/longdate.in @@ -0,0 +1,5 @@ +.TH TH-LONGDATE 1 "1234567890123456789012345678901234567890123456789012345678901234567890123456789012" source +.SH NAME +TH-longdate \- the date is longer than the line length +.SH DESCRIPTION +Some text. diff --git a/regress/usr.bin/mandoc/man/TH/longdate.out_ascii b/regress/usr.bin/mandoc/man/TH/longdate.out_ascii new file mode 100644 index 00000000000..4578834bff3 --- /dev/null +++ b/regress/usr.bin/mandoc/man/TH/longdate.out_ascii @@ -0,0 +1,15 @@ +TH-LONGDATE(1) General Commands Manual TH-LONGDATE(1) + + + +NNAAMMEE + TH-longdate - the date is longer than the line length + +DDEESSCCRRIIPPTTIIOONN + Some text. + + + +source +1234567890123456789012345678901234567890123456789012345678901234567890123456789012 + TH-LONGDATE(1) diff --git a/regress/usr.bin/mandoc/man/TH/longdate.out_lint b/regress/usr.bin/mandoc/man/TH/longdate.out_lint new file mode 100644 index 00000000000..87add528c80 --- /dev/null +++ b/regress/usr.bin/mandoc/man/TH/longdate.out_lint @@ -0,0 +1 @@ +mandoc: longdate.in:1:19: WARNING: cannot parse date, using it verbatim: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012 diff --git a/regress/usr.bin/mandoc/man/TH/longtit.in b/regress/usr.bin/mandoc/man/TH/longtit.in new file mode 100644 index 00000000000..f0b66b97139 --- /dev/null +++ b/regress/usr.bin/mandoc/man/TH/longtit.in @@ -0,0 +1,5 @@ +.TH TH-LONGTIT-23456789012345678901234567890123456789012345678901234567890123456789 1 "November 20, 2014" source +.SH NAME +TH-longtit \- the title is longer than the line length +.SH DESCRIPTION +Some text. diff --git a/regress/usr.bin/mandoc/man/TH/longtit.out_ascii b/regress/usr.bin/mandoc/man/TH/longtit.out_ascii new file mode 100644 index 00000000000..00dbe254e67 --- /dev/null +++ b/regress/usr.bin/mandoc/man/TH/longtit.out_ascii @@ -0,0 +1,15 @@ +TH-LONGTIT-23456789012345678901234567890123456789012345678901234567890123456789(1) + General Commands Manual + + + +NNAAMMEE + TH-longtit - the title is longer than the line length + +DDEESSCCRRIIPPTTIIOONN + Some text. + + + +source November 20, 2014 +TH-LONGTIT-23456789012345678901234567890123456789012345678901234567890123456789(1) diff --git a/regress/usr.bin/mandoc/man/TH/longvol.in b/regress/usr.bin/mandoc/man/TH/longvol.in new file mode 100644 index 00000000000..2b6d0f1f848 --- /dev/null +++ b/regress/usr.bin/mandoc/man/TH/longvol.in @@ -0,0 +1,5 @@ +.TH TH-LONGVOL 1 "November 20, 2014" source 1234567890123456789012345678901234567890123456789012345678901234567890123456789 +.SH NAME +TH-longvol \- the volume string is longer than the line length +.SH DESCRIPTION +Some text. diff --git a/regress/usr.bin/mandoc/man/TH/longvol.out_ascii b/regress/usr.bin/mandoc/man/TH/longvol.out_ascii new file mode 100644 index 00000000000..bdc881a8256 --- /dev/null +++ b/regress/usr.bin/mandoc/man/TH/longvol.out_ascii @@ -0,0 +1,14 @@ +TH-LONGVOL(1) +1234567890123456789012345678901234567890123456789012345678901234567890123456789 + + + +NNAAMMEE + TH-longvol - the volume string is longer than the line length + +DDEESSCCRRIIPPTTIIOONN + Some text. + + + +source November 20, 2014 TH-LONGVOL(1) diff --git a/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.in b/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.in index ec0d8a1b48a..32f2a593239 100644 --- a/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.in +++ b/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.in @@ -1,4 +1,4 @@ -.Dd October 30, 2014 +.Dd November 20, 2014 .Dt BD-OFFSET-EMPTY 1 .Os OpenBSD .Sh NAME @@ -26,3 +26,6 @@ Bd literal offset mystring .Bd -literal -offset Ds Bd literal offset Ds .Ed +.Bd -literal -offset 78n +Bd literal offset 78n +.Ed diff --git a/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.out_ascii b/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.out_ascii index 8552fe804c0..e4e2659c3ef 100644 --- a/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.out_ascii +++ b/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.out_ascii @@ -18,4 +18,6 @@ DDEESSCCRRIIPPTTIIOONN Bd literal offset Ds -OpenBSD October 30, 2014 OpenBSD + Bd literal offset 78n + +OpenBSD November 20, 2014 OpenBSD diff --git a/regress/usr.bin/mandoc/mdoc/Bl/offset.in b/regress/usr.bin/mandoc/mdoc/Bl/offset.in index ca36c545f5f..4e5b334fbda 100644 --- a/regress/usr.bin/mandoc/mdoc/Bl/offset.in +++ b/regress/usr.bin/mandoc/mdoc/Bl/offset.in @@ -1,4 +1,4 @@ -.Dd October 30, 2014 +.Dd November 20, 2014 .Dt BL-OFFSET 1 .Os OpenBSD .Sh NAME @@ -33,6 +33,10 @@ Bl item offset mystring .It Bl item offset Ds .El +.Bl -item -offset 78n +.It +Bl item offset 78n +.El .Bl -tag -width Ds -offset .It tag Bl tag width Ds offset empty @@ -61,3 +65,7 @@ Bl tag width Ds offset mystring .It tag Bl tag width Ds offset Ds .El +.Bl -tag -width Ds -offset 78n +.It tag +Bl tag width Ds offset 78n +.El diff --git a/regress/usr.bin/mandoc/mdoc/Bl/offset.out_ascii b/regress/usr.bin/mandoc/mdoc/Bl/offset.out_ascii index 4c2cdeb3929..345b583870b 100644 --- a/regress/usr.bin/mandoc/mdoc/Bl/offset.out_ascii +++ b/regress/usr.bin/mandoc/mdoc/Bl/offset.out_ascii @@ -18,6 +18,11 @@ DDEESSCCRRIIPPTTIIOONN Bl item offset Ds + Bl + item + offset + 78n + tag Bl tag width Ds offset empty tag Bl tag width Ds offset left @@ -32,4 +37,11 @@ DDEESSCCRRIIPPTTIIOONN tag Bl tag width Ds offset Ds -OpenBSD October 30, 2014 OpenBSD + tag Bl + tag + width + Ds + offset + 78n + +OpenBSD November 20, 2014 OpenBSD diff --git a/regress/usr.bin/mandoc/mdoc/Dd/Makefile b/regress/usr.bin/mandoc/mdoc/Dd/Makefile index d1c890d1bdb..e50e9b6101f 100644 --- a/regress/usr.bin/mandoc/mdoc/Dd/Makefile +++ b/regress/usr.bin/mandoc/mdoc/Dd/Makefile @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile,v 1.1 2014/08/14 02:00:52 schwarze Exp $ +# $OpenBSD: Makefile,v 1.2 2014/11/21 01:52:45 schwarze Exp $ -REGRESS_TARGETS = badarg dupe late manarg noarg order -LINT_TARGETS = badarg dupe late manarg noarg order +REGRESS_TARGETS = badarg dupe late long manarg noarg order +LINT_TARGETS = badarg dupe late long manarg noarg order # If groff finds exactly three arguments, it assumes they are month, # day and year without further checking. If there are no arguments, @@ -9,7 +9,7 @@ LINT_TARGETS = badarg dupe late manarg noarg order # to today's date. # That is not at all sane behaviour, we are not going to imitate it. -SKIP_GROFF = badarg manarg noarg +SKIP_GROFF = badarg long manarg noarg SKIP_ASCII = noarg # Autodetection fails for late .Dd, so specify -mdoc explicitly. diff --git a/regress/usr.bin/mandoc/mdoc/Dd/long.in b/regress/usr.bin/mandoc/mdoc/Dd/long.in new file mode 100644 index 00000000000..2538f984feb --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Dd/long.in @@ -0,0 +1,8 @@ +.Dd 1234567890123456789012345678901234567890123456789012345678901234567890123456789 +.Dt DD-LONG 1 +.Os OpenBSD +.Sh NAME +.Nm Dd-long +.Nd long date string +.Sh DESCRIPTION +some text diff --git a/regress/usr.bin/mandoc/mdoc/Dd/long.out_ascii b/regress/usr.bin/mandoc/mdoc/Dd/long.out_ascii new file mode 100644 index 00000000000..69811af2771 --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Dd/long.out_ascii @@ -0,0 +1,11 @@ +DD-LONG(1) General Commands Manual DD-LONG(1) + +NNAAMMEE + DDdd--lloonngg - long date string + +DDEESSCCRRIIPPTTIIOONN + some text + +OpenBSD +1234567890123456789012345678901234567890123456789012345678901234567890123456789 + OpenBSD diff --git a/regress/usr.bin/mandoc/mdoc/Dd/long.out_lint b/regress/usr.bin/mandoc/mdoc/Dd/long.out_lint new file mode 100644 index 00000000000..d74ed9e2b95 --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Dd/long.out_lint @@ -0,0 +1 @@ +mandoc: long.in:1:2: WARNING: cannot parse date, using it verbatim: 1234567890123456789012345678901234567890123456789012345678901234567890123456789 diff --git a/regress/usr.bin/mandoc/mdoc/Os/Makefile b/regress/usr.bin/mandoc/mdoc/Os/Makefile index 7dd662c48f6..d228b09d1f7 100644 --- a/regress/usr.bin/mandoc/mdoc/Os/Makefile +++ b/regress/usr.bin/mandoc/mdoc/Os/Makefile @@ -1,6 +1,7 @@ -# $OpenBSD: Makefile,v 1.1 2014/08/14 02:00:53 schwarze Exp $ +# $OpenBSD: Makefile,v 1.2 2014/11/21 01:52:45 schwarze Exp $ -REGRESS_TARGETS = dupe late missing +REGRESS_TARGETS = dupe late long missing LINT_TARGETS = dupe late missing +SKIP_GROFF = long .include <bsd.regress.mk> diff --git a/regress/usr.bin/mandoc/mdoc/Os/long.in b/regress/usr.bin/mandoc/mdoc/Os/long.in new file mode 100644 index 00000000000..c4998629cbb --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Os/long.in @@ -0,0 +1,8 @@ +.Dd November 20, 2014 +.Dt OS-LONG 1 +.Os 1234567890123456789012345678901234567890123456789012345678901234567890123456789 +.Sh NAME +.Nm Os-long +.Nd long operating system string +.Sh DESCRIPTION +some text diff --git a/regress/usr.bin/mandoc/mdoc/Os/long.out_ascii b/regress/usr.bin/mandoc/mdoc/Os/long.out_ascii new file mode 100644 index 00000000000..9253e13e097 --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Os/long.out_ascii @@ -0,0 +1,11 @@ +OS-LONG(1) General Commands Manual OS-LONG(1) + +NNAAMMEE + OOss--lloonngg - long operating system string + +DDEESSCCRRIIPPTTIIOONN + some text + +1234567890123456789012345678901234567890123456789012345678901234567890123456789 + November 20, 2014 +1234567890123456789012345678901234567890123456789012345678901234567890123456789 diff --git a/regress/usr.bin/mandoc/roff/scale/horiz.in b/regress/usr.bin/mandoc/roff/scale/horiz.in index 89434db98b4..cd74e7ccfe6 100644 --- a/regress/usr.bin/mandoc/roff/scale/horiz.in +++ b/regress/usr.bin/mandoc/roff/scale/horiz.in @@ -1,4 +1,4 @@ -.TH HORIZ 1 "August 12, 2014" OpenBSD +.TH HORIZ 1 "November 20, 2014" OpenBSD .SH NAME horiz \- horizontal distances .SH DESCRIPTION @@ -21,5 +21,7 @@ initial text 10n .in 5m 5m +.in 79n +79n .PP final text diff --git a/regress/usr.bin/mandoc/roff/scale/horiz.out_ascii b/regress/usr.bin/mandoc/roff/scale/horiz.out_ascii index e138965ce94..5c7f1d5fbad 100644 --- a/regress/usr.bin/mandoc/roff/scale/horiz.out_ascii +++ b/regress/usr.bin/mandoc/roff/scale/horiz.out_ascii @@ -16,9 +16,10 @@ DDEESSCCRRIIPPTTIIOONN 36p 10n 5m + 79n final text -OpenBSD August 12, 2014 HORIZ(1) +OpenBSD November 20, 2014 HORIZ(1) diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index cb74c28fb24..19f17b975c1 100644 --- a/usr.bin/mandoc/man_term.c +++ b/usr.bin/mandoc/man_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_term.c,v 1.108 2014/10/28 17:35:42 schwarze Exp $ */ +/* $OpenBSD: man_term.c,v 1.109 2014/11/21 01:52:44 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -454,11 +454,6 @@ pre_in(DECL_ARGS) else p->offset = v; - /* Don't let this creep beyond the right margin. */ - - if (p->offset > p->rmargin) - p->offset = p->rmargin; - return(0); } @@ -652,8 +647,7 @@ pre_IP(DECL_ARGS) return(0); case MAN_BODY: p->offset = mt->offset + len; - p->rmargin = p->maxrmargin > p->offset ? - p->maxrmargin : p->offset; + p->rmargin = p->maxrmargin; break; default: break; @@ -744,8 +738,7 @@ pre_TP(DECL_ARGS) return(0); case MAN_BODY: p->offset = mt->offset + len; - p->rmargin = p->maxrmargin > p->offset ? - p->maxrmargin : p->offset; + p->rmargin = p->maxrmargin; p->trailspace = 0; p->flags &= ~TERMP_NOBREAK; break; @@ -896,8 +889,7 @@ pre_RS(DECL_ARGS) mt->offset += sz; p->offset = mt->offset; - p->rmargin = p->maxrmargin > p->offset ? - p->maxrmargin : p->offset; + p->rmargin = p->maxrmargin; if (++mt->lmarginsz < MAXMARGINS) mt->lmargincur = mt->lmarginsz; @@ -1061,7 +1053,7 @@ print_man_foot(struct termp *p, const void *arg) { const struct man_meta *meta; char *title; - size_t datelen; + size_t datelen, titlen; meta = (const struct man_meta *)arg; assert(meta->title); @@ -1098,7 +1090,8 @@ print_man_foot(struct termp *p, const void *arg) p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; p->trailspace = 1; p->offset = 0; - p->rmargin = (p->maxrmargin - datelen + term_len(p, 1)) / 2; + p->rmargin = p->maxrmargin > datelen ? + (p->maxrmargin + term_len(p, 1) - datelen) / 2 : 0; if (meta->source) term_word(p, meta->source); @@ -1106,11 +1099,10 @@ print_man_foot(struct termp *p, const void *arg) /* At the bottom in the middle: manual date. */ - p->flags |= TERMP_NOSPACE; p->offset = p->rmargin; - p->rmargin = p->maxrmargin - term_strlen(p, title); - if (p->offset + datelen >= p->rmargin) - p->rmargin = p->offset + datelen; + titlen = term_strlen(p, title); + p->rmargin = p->maxrmargin > titlen ? p->maxrmargin - titlen : 0; + p->flags |= TERMP_NOSPACE; term_word(p, meta->date); term_flushln(p); @@ -1153,7 +1145,7 @@ print_man_head(struct termp *p, const void *arg) p->offset = 0; p->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ? (p->maxrmargin - vollen + term_len(p, 1)) / 2 : - p->maxrmargin - vollen; + vollen < p->maxrmargin ? p->maxrmargin - vollen : 0; term_word(p, title); term_flushln(p); diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index e74a951f336..c91170f3359 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_term.c,v 1.190 2014/11/19 21:59:19 schwarze Exp $ */ +/* $OpenBSD: mdoc_term.c,v 1.191 2014/11/21 01:52:44 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -403,6 +403,7 @@ static void print_mdoc_foot(struct termp *p, const void *arg) { const struct mdoc_meta *meta; + size_t sz; meta = (const struct mdoc_meta *)arg; @@ -419,8 +420,9 @@ print_mdoc_foot(struct termp *p, const void *arg) term_vspace(p); p->offset = 0; - p->rmargin = (p->maxrmargin - - term_strlen(p, meta->date) + term_len(p, 1)) / 2; + sz = term_strlen(p, meta->date); + p->rmargin = p->maxrmargin > sz ? + (p->maxrmargin + term_len(p, 1) - sz) / 2 : 0; p->trailspace = 1; p->flags |= TERMP_NOSPACE | TERMP_NOBREAK; @@ -428,7 +430,8 @@ print_mdoc_foot(struct termp *p, const void *arg) term_flushln(p); p->offset = p->rmargin; - p->rmargin = p->maxrmargin - term_strlen(p, meta->os); + sz = term_strlen(p, meta->os); + p->rmargin = p->maxrmargin > sz ? p->maxrmargin - sz : 0; p->flags |= TERMP_NOSPACE; term_word(p, meta->date); @@ -490,7 +493,7 @@ print_mdoc_head(struct termp *p, const void *arg) p->offset = 0; p->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ? (p->maxrmargin - vollen + term_len(p, 1)) / 2 : - p->maxrmargin - vollen; + vollen < p->maxrmargin ? p->maxrmargin - vollen : 0; term_word(p, title); term_flushln(p); @@ -871,11 +874,8 @@ termp_it_pre(DECL_ARGS) assert(width); if (MDOC_HEAD == n->type) p->rmargin = p->offset + width; - else { + else p->offset += width; - if (p->rmargin < p->offset) - p->rmargin = p->offset; - } break; case LIST_column: assert(width); @@ -1008,8 +1008,6 @@ termp_nm_pre(DECL_ARGS) MDOC_TEXT == n->prev->child->type ? term_strlen(p, n->prev->child->string) : term_len(p, 5)); - if (p->rmargin < p->offset) - p->rmargin = p->offset; return(1); } diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c index add5ec877cc..39d5e8ebd62 100644 --- a/usr.bin/mandoc/term.c +++ b/usr.bin/mandoc/term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term.c,v 1.95 2014/11/16 21:29:27 schwarze Exp $ */ +/* $OpenBSD: term.c,v 1.96 2014/11/21 01:52:45 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -98,7 +98,7 @@ term_flushln(struct termp *p) size_t j; /* temporary loop index for p->buf */ size_t jhy; /* last hyph before overflow w/r/t j */ size_t maxvis; /* output position of visible boundary */ - size_t mmax; /* used in calculating bp */ + size_t rmargin; /* the rightmost of the two margins */ /* * First, establish the maximum columns of "visible" content. @@ -111,13 +111,17 @@ term_flushln(struct termp *p) * is negative, it gets sign extended. Subtracting that * very large size_t effectively adds a small number to dv. */ - assert (p->rmargin >= p->offset); - dv = p->rmargin - p->offset; + rmargin = p->rmargin > p->offset ? p->rmargin : p->offset; + dv = p->rmargin - p->offset; maxvis = (int)dv > p->overstep ? dv - (size_t)p->overstep : 0; - dv = p->maxrmargin - p->offset; - mmax = (int)dv > p->overstep ? dv - (size_t)p->overstep : 0; - bp = TERMP_NOBREAK & p->flags ? mmax : maxvis; + if (p->flags & TERMP_NOBREAK) { + dv = p->maxrmargin > p->offset ? + p->maxrmargin - p->offset : 0; + bp = (int)dv > p->overstep ? + dv - (size_t)p->overstep : 0; + } else + bp = maxvis; /* * Calculate the required amount of padding. @@ -186,8 +190,8 @@ term_flushln(struct termp *p) (*p->endline)(p); p->viscol = 0; if (TERMP_BRIND & p->flags) { - vbl = p->rmargin; - vend += p->rmargin - p->offset; + vbl = rmargin; + vend += rmargin - p->offset; } else vbl = p->offset; |