At the end of every tbl(7) cell, clear the \z state.
authorschwarze <schwarze@openbsd.org>
Tue, 26 Apr 2022 14:46:30 +0000 (14:46 +0000)
committerschwarze <schwarze@openbsd.org>
Tue, 26 Apr 2022 14:46:30 +0000 (14:46 +0000)
This is needed because the TERMP_MULTICOL mode is designed such
that term_tbl() buffers all the cells of the table row before the
normal reset logic near the end of term_flushln() can be reached.

This fixes an assertion failure triggered by \z near the end
of a table cell, found by tb@ using afl(1).

regress/usr.bin/mandoc/tbl/data/Makefile
regress/usr.bin/mandoc/tbl/data/escz.in [new file with mode: 0644]
regress/usr.bin/mandoc/tbl/data/escz.out_ascii [new file with mode: 0644]
regress/usr.bin/mandoc/tbl/data/escz_end.in [new file with mode: 0644]
regress/usr.bin/mandoc/tbl/data/escz_end.out_ascii [new file with mode: 0644]
usr.bin/mandoc/tbl_term.c

index b1dcfa0..6db686b 100644 (file)
@@ -1,13 +1,16 @@
-# $OpenBSD: Makefile,v 1.5 2019/07/18 14:38:47 schwarze Exp $
+# $OpenBSD: Makefile,v 1.6 2022/04/26 14:46:30 schwarze Exp $
 
 REGRESS_TARGETS         = blankline block_empty block_unclosed block_width
-REGRESS_TARGETS        += block_wrap empty insert
+REGRESS_TARGETS        += block_wrap empty escz escz_end insert
 LINT_TARGETS    = block_unclosed empty insert
 
-# groff-1.22.3 defect:
+# groff-1.23.0 defects:
 # - When a table ends in the middle of a block,
 #   GNU eqn produces no output whatsoever for the whole table.
+# - When a table cell ends with a no-advance escape sequence,
+#   the next cell is appended to the current cell instead of
+#   aligning it to the next column.
 
-SKIP_GROFF      = block_unclosed
+SKIP_GROFF      = block_unclosed escz_end
 
 .include <bsd.regress.mk>
diff --git a/regress/usr.bin/mandoc/tbl/data/escz.in b/regress/usr.bin/mandoc/tbl/data/escz.in
new file mode 100644 (file)
index 0000000..406df48
--- /dev/null
@@ -0,0 +1,14 @@
+.\" $OpenBSD: escz.in,v 1.1 2022/04/26 14:46:30 schwarze Exp $
+.TH TBL-DATA-ESCZ 1 "April 26, 2022"
+.SH NAME
+tbl-data-escz \- non-advancing glyph at the end of a tbl(7) cell
+.SH DESCRIPTION
+initial text
+.TS
+tab(:);
+LL.
+a:b
+c\zd:e
+.TE
+.sp
+final text
diff --git a/regress/usr.bin/mandoc/tbl/data/escz.out_ascii b/regress/usr.bin/mandoc/tbl/data/escz.out_ascii
new file mode 100644 (file)
index 0000000..486ab3d
--- /dev/null
@@ -0,0 +1,14 @@
+TBL-DATA-ESCZ(1)            General Commands Manual           TBL-DATA-ESCZ(1)
+
+N\bNA\bAM\bME\bE
+       tbl-data-escz - non-advancing glyph at the end of a tbl(7) cell
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+       initial text
+
+       a   b
+       cd  e
+
+       final text
+
+OpenBSD                         April 26, 2022                TBL-DATA-ESCZ(1)
diff --git a/regress/usr.bin/mandoc/tbl/data/escz_end.in b/regress/usr.bin/mandoc/tbl/data/escz_end.in
new file mode 100644 (file)
index 0000000..5149f5d
--- /dev/null
@@ -0,0 +1,14 @@
+.\" $OpenBSD: escz_end.in,v 1.1 2022/04/26 14:46:30 schwarze Exp $
+.TH TBL-DATA-ESCZ_END 1 "April 26, 2022"
+.SH NAME
+tbl-data-escz_end \- z escape sequence at the end of a tbl(7) cell
+.SH DESCRIPTION
+initial text
+.TS
+tab(:);
+LLL.
+a:b:c
+d\z:e:f
+.TE
+.sp
+final text
diff --git a/regress/usr.bin/mandoc/tbl/data/escz_end.out_ascii b/regress/usr.bin/mandoc/tbl/data/escz_end.out_ascii
new file mode 100644 (file)
index 0000000..f195c9c
--- /dev/null
@@ -0,0 +1,14 @@
+TBL-DATA-ESCZ_END(1)        General Commands Manual       TBL-DATA-ESCZ_END(1)
+
+N\bNA\bAM\bME\bE
+       tbl-data-escz_end - z escape sequence at the end of a tbl(7) cell
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+       initial text
+
+       a   b   c
+       d   e   f
+
+       final text
+
+OpenBSD                         April 26, 2022            TBL-DATA-ESCZ_END(1)
index c054fde..f20aec9 100644 (file)
@@ -1,7 +1,7 @@
-/*     $OpenBSD: tbl_term.c,v 1.64 2022/04/08 16:53:40 schwarze Exp $ */
+/* $OpenBSD: tbl_term.c,v 1.65 2022/04/26 14:46:30 schwarze Exp $ */
 /*
+ * Copyright (c) 2011-2022 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011-2021 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -288,6 +288,7 @@ term_tbl(struct termp *tp, const struct tbl_span *sp)
                        }
                        tp->tcol++;
                        tp->col = 0;
+                       tp->flags &= ~(TERMP_BACKAFTER | TERMP_BACKBEFORE);
                        tbl_data(tp, sp->opts, cp, dp, tp->tbl.cols + ic);
                        if (dp != NULL &&
                            (ic || sp->layout->first->pos != TBL_CELL_SPAN)) {