Module Name:    src
Committed By:   christos
Date:           Fri Mar 29 22:00:31 UTC 2019

Modified Files:
        src/external/bsd/mdocml/dist: out.c

Log Message:
Set the maximum column index in a tbl(7) to the maximum *right* edge
of any cell span, not to the maximum *left* edge, which may be smaller
if the last column of the table is only reached by horizontal spans,
but not by any regular cell in any row of the table.
Otherwise, the algorithm calculating column widths accessed memomy
after the end of the colwidth[] array, while it was trying to handle
the rightmost column(s).

Crash reported by Jason Thorpe <thorpej at NetBSD>
via https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=54069
and via Thomas Klausner (wiz@).
Christos@ Zoulas sent a (correct, but slightly confusing) patch.
The patch i'm committing here is easier to understand.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/external/bsd/mdocml/dist/out.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/mdocml/dist/out.c
diff -u src/external/bsd/mdocml/dist/out.c:1.4 src/external/bsd/mdocml/dist/out.c:1.5
--- src/external/bsd/mdocml/dist/out.c:1.4	Thu Mar 28 16:26:49 2019
+++ src/external/bsd/mdocml/dist/out.c	Fri Mar 29 18:00:31 2019
@@ -149,7 +149,7 @@ tblcalc(struct rofftbl *tbl, const struc
 		gp = &first_group;
 		for (dp = sp->first; dp != NULL; dp = dp->next) {
 			icol = dp->layout->col;
-			while (icol > maxcol)
+			while (maxcol < icol + dp->hspans)
 				tbl->cols[++maxcol].spacing = SIZE_MAX;
 			col = tbl->cols + icol;
 			col->flags |= dp->layout->flags;
@@ -235,9 +235,6 @@ tblcalc(struct rofftbl *tbl, const struc
 			} else
 				(*gp)->wanted -= width;
 		}
-		if (g->endcol > maxcol) {
-			maxcol = g->endcol;
-		}
 		if (done) {
 			*gp = g->next;
 			free(g);

Reply via email to