=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/term.c,v retrieving revision 1.72 retrieving revision 1.73 diff -u -r1.72 -r1.73 --- src/usr.bin/mandoc/term.c 2013/12/22 23:33:52 1.72 +++ src/usr.bin/mandoc/term.c 2013/12/23 02:19:57 1.73 @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.72 2013/12/22 23:33:52 schwarze Exp $ */ +/* $Id: term.c,v 1.73 2013/12/23 02:19:57 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze @@ -116,7 +116,12 @@ * First, establish the maximum columns of "visible" content. * This is usually the difference between the right-margin and * an indentation, but can be, for tagged lists or columns, a - * small set of values. + * small set of values. + * + * The following unsigned-signed subtractions look strange, + * but they are actually correct. If the int p->overstep + * 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; @@ -195,7 +200,11 @@ if (0 < ntab) vbl += ntab * p->tabwidth; - /* Remove the p->overstep width. */ + /* + * Remove the p->overstep width. + * Again, if p->overstep is negative, + * sign extension does the right thing. + */ bp += (size_t)p->overstep; p->overstep = 0; @@ -271,8 +280,10 @@ * If we have overstepped the margin, temporarily move * it to the right and flag the rest of the line to be * shorter. + * If there is a request to keep the columns together, + * allow negative overstep when the column is not full. */ - if (p->overstep < 0) + if (p->trailspace && p->overstep < 0) p->overstep = 0; return;