source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: Element next-line scopes may nest, so man_breakscope() may have
@ 2022-04-28 10:26 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2022-04-28 10:26 UTC (permalink / raw)
  To: source

Log Message:
-----------
Element next-line scopes may nest, so man_breakscope() may have to
break multiple element next-line scopes at the same time, similar to
what man_descope() already does for unconditional rewinding.

This fixes an assertion failure that tb@ found with afl(1), caused
by .SH .I .I .BI and similar sequences of macros without arguments.

Modified Files:
--------------
    mandoc:
        man.c
    mandoc/regress/man/B:
        Makefile

Added Files:
-----------
    mandoc/regress/man/B:
        nest.in
        nest.out_ascii
        nest.out_lint

Revision Data
-------------
Index: man.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man.c,v
retrieving revision 1.187
retrieving revision 1.188
diff -Lman.c -Lman.c -u -p -r1.187 -r1.188
--- man.c
+++ man.c
@@ -1,7 +1,7 @@
-/*	$Id$ */
+/* $Id$ */
 /*
+ * Copyright (c) 2013-2015,2017-2019,2022 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013-2015, 2017-2019 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2011 Joerg Sonnenberger <joerg@netbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -70,6 +70,9 @@ man_hasc(char *start)
 	return (ep - cp) % 2 ? NULL : ep;
 }
 
+/*
+ * Rewind all open next-line scopes.
+ */
 void
 man_descope(struct roff_man *man, int line, int offs, char *start)
 {
@@ -274,6 +277,10 @@ man_pmacro(struct roff_man *man, int ln,
 	return 1;
 }
 
+/*
+ * Rewind open next-line scopes
+ * unless the tok request or macro is allowed inside them.
+ */
 void
 man_breakscope(struct roff_man *man, int tok)
 {
@@ -294,10 +301,15 @@ man_breakscope(struct roff_man *man, int
 		    (man_macro(n->tok)->flags & (MAN_NSCOPED | MAN_ESCOPED))
 		     == MAN_NSCOPED)
 			n = n->parent;
-
-		mandoc_msg(MANDOCERR_BLK_LINE, n->line, n->pos,
-		    "%s breaks %s", roff_name[tok], roff_name[n->tok]);
-
+		for (;;) {
+			mandoc_msg(MANDOCERR_BLK_LINE, n->line, n->pos,
+			    "%s breaks %s", roff_name[tok], roff_name[n->tok]);
+			if (n->parent->type != ROFFT_ELEM ||
+			    (man_macro(n->parent->tok)->flags &
+			     MAN_ESCOPED) == 0)
+				break;
+			n = n->parent;
+		}
 		roff_node_delete(man, n);
 		man->flags &= ~MAN_ELINE;
 	}
--- /dev/null
+++ regress/man/B/nest.out_lint
@@ -0,0 +1,6 @@
+mandoc: nest.in:12:2: WARNING: line scope broken: IR breaks SM
+mandoc: nest.in:11:2: WARNING: line scope broken: IR breaks B
+mandoc: nest.in:15:2: WARNING: line scope broken: SH breaks SM
+mandoc: nest.in:14:2: WARNING: line scope broken: SH breaks B
+mandoc: nest.in:18:2: WARNING: line scope broken: RI breaks B
+mandoc: nest.in:17:2: WARNING: line scope broken: RI breaks B
--- /dev/null
+++ regress/man/B/nest.out_ascii
@@ -0,0 +1,12 @@
+B-NEST(1)                   General Commands Manual                  B-NEST(1)
+
+N\bNA\bAM\bME\bE
+       B-nest - nested next-line scopes
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+       initial text b\bbo\bol\bld\bd t\bte\bex\bxt\bt back to roman _\bi_\bt_\ba_\bl_\bi_\bcroman
+
+section_\bh_\be_\ba_\bd_\be_\br
+       final text
+
+OpenBSD                         April 28, 2022                       B-NEST(1)
--- /dev/null
+++ regress/man/B/nest.in
@@ -0,0 +1,20 @@
+.\" $OpenBSD: nest.in,v 1.2 2022/04/28 10:23:31 schwarze Exp $
+.TH B-NEST 1 "April 28, 2022"
+.SH NAME
+B-nest \- nested next-line scopes
+.SH DESCRIPTION
+initial text
+.B
+.SM
+bold text
+back to roman
+.B
+.SM
+.IR italic roman
+.B
+.SM
+.SH
+.B
+.B
+.RI section header
+final text
Index: Makefile
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/man/B/Makefile,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lregress/man/B/Makefile -Lregress/man/B/Makefile -u -p -r1.2 -r1.3
--- regress/man/B/Makefile
+++ regress/man/B/Makefile
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile,v 1.1 2014/08/14 02:00:52 schwarze Exp $
+# $OpenBSD: Makefile,v 1.3 2022/04/28 10:17:38 schwarze Exp $
 
-REGRESS_TARGETS	= args blank
-LINT_TARGETS	= args blank
+REGRESS_TARGETS	= args blank nest
+LINT_TARGETS	= args blank nest
 
 # groff-1.22.3 defect:
 # - A blank line in next line scope causes a blank line.
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-28 10:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-28 10:26 mandoc: Element next-line scopes may nest, so man_breakscope() may have schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).