If a node is tagged explicitly, skip implicit tagging for that node.
authorschwarze <schwarze@openbsd.org>
Tue, 26 Apr 2022 11:28:35 +0000 (11:28 +0000)
committerschwarze <schwarze@openbsd.org>
Tue, 26 Apr 2022 11:28:35 +0000 (11:28 +0000)
Apart from making sense in the first place, this fixes an assertion
failure that happened when the calculated implicit tag did not match
the string value of the first child of the node,

Bug found by tb@ using afl(1).

regress/usr.bin/mandoc/mdoc/Tg/Makefile
regress/usr.bin/mandoc/mdoc/Tg/implicit.in [new file with mode: 0644]
regress/usr.bin/mandoc/mdoc/Tg/implicit.out_ascii [new file with mode: 0644]
regress/usr.bin/mandoc/mdoc/Tg/implicit.out_html [new file with mode: 0644]
regress/usr.bin/mandoc/mdoc/Tg/implicit.out_markdown [new file with mode: 0644]
regress/usr.bin/mandoc/mdoc/Tg/implicit.out_tag [new file with mode: 0644]
usr.bin/mandoc/tag.c

index d67ec5a..83ae416 100644 (file)
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile,v 1.2 2020/04/06 09:55:50 schwarze Exp $
+# $OpenBSD: Makefile,v 1.3 2022/04/26 11:28:35 schwarze Exp $
 
-REGRESS_TARGETS = column list warn
-TAG_TARGETS    = column list warn
+REGRESS_TARGETS = column implicit list warn
+TAG_TARGETS    = column implicit list warn
 LINT_TARGETS   = warn
-HTML_TARGETS   = column list warn
+HTML_TARGETS   = column implicit list warn
 
 SKIP_TMAN      = column
 
diff --git a/regress/usr.bin/mandoc/mdoc/Tg/implicit.in b/regress/usr.bin/mandoc/mdoc/Tg/implicit.in
new file mode 100644 (file)
index 0000000..9abd23c
--- /dev/null
@@ -0,0 +1,14 @@
+.\" $OpenBSD: implicit.in,v 1.1 2022/04/26 11:28:35 schwarze Exp $
+.Dd $Mdocdate: April 26 2022 $
+.Dt TG-IMPLICIT 1
+.Os
+.Sh NAME
+.Nm Tg-implicit
+.Nd overriding implicit tagging
+.Sh DESCRIPTION
+BEGINTEST
+.Pp
+.Tg explicit
+.Sy implicit is unsused
+.Pp
+ENDTEST
diff --git a/regress/usr.bin/mandoc/mdoc/Tg/implicit.out_ascii b/regress/usr.bin/mandoc/mdoc/Tg/implicit.out_ascii
new file mode 100644 (file)
index 0000000..e361868
--- /dev/null
@@ -0,0 +1,13 @@
+TG-IMPLICIT(1)              General Commands Manual             TG-IMPLICIT(1)
+
+N\bNA\bAM\bME\bE
+     T\bTg\bg-\b-i\bim\bmp\bpl\bli\bic\bci\bit\bt - overriding implicit tagging
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+     BEGINTEST
+
+     i\bim\bmp\bpl\bli\bic\bci\bit\bt i\bis\bs u\bun\bns\bsu\bus\bse\bed\bd
+
+     ENDTEST
+
+OpenBSD                         April 26, 2022                         OpenBSD
diff --git a/regress/usr.bin/mandoc/mdoc/Tg/implicit.out_html b/regress/usr.bin/mandoc/mdoc/Tg/implicit.out_html
new file mode 100644 (file)
index 0000000..93df918
--- /dev/null
@@ -0,0 +1,2 @@
+<p class="Pp" id="explicit"><a class="permalink" href="#explicit"><b class="Sy">implicit
+    is unsused</b></a></p>
diff --git a/regress/usr.bin/mandoc/mdoc/Tg/implicit.out_markdown b/regress/usr.bin/mandoc/mdoc/Tg/implicit.out_markdown
new file mode 100644 (file)
index 0000000..6511e44
--- /dev/null
@@ -0,0 +1,15 @@
+TG-IMPLICIT(1) - General Commands Manual
+
+# NAME
+
+**Tg-implicit** - overriding implicit tagging
+
+# DESCRIPTION
+
+BEGINTEST
+
+**implicit is unsused**
+
+ENDTEST
+
+OpenBSD - April 26, 2022
diff --git a/regress/usr.bin/mandoc/mdoc/Tg/implicit.out_tag b/regress/usr.bin/mandoc/mdoc/Tg/implicit.out_tag
new file mode 100644 (file)
index 0000000..b7b9a92
--- /dev/null
@@ -0,0 +1,3 @@
+NAME implicit.mandoc_ascii 3
+DESCRIPTION implicit.mandoc_ascii 6
+explicit implicit.mandoc_ascii 9
index 6db87cc..8cb7bdb 100644 (file)
@@ -1,6 +1,7 @@
-/* $OpenBSD: tag.c,v 1.36 2020/04/19 16:26:11 schwarze Exp $ */
+/* $OpenBSD: tag.c,v 1.37 2022/04/26 11:28:35 schwarze Exp $ */
 /*
- * Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2015, 2016, 2018, 2019, 2020, 2022
+ *               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
@@ -78,7 +79,7 @@ tag_free(void)
 
 /*
  * Set a node where a term is defined,
- * unless it is already defined at a lower priority.
+ * unless the term is already defined at a lower priority.
  */
 void
 tag_put(const char *s, int prio, struct roff_node *n)
@@ -91,6 +92,18 @@ tag_put(const char *s, int prio, struct roff_node *n)
 
        assert(prio <= TAG_FALLBACK);
 
+       /*
+        * If the node is already tagged, the existing tag is
+        * explicit and we are now about to add an implicit tag.
+        * Don't do that; just skip implicit tagging if the author
+        * specified an explicit tag.
+        */
+
+       if (n->flags & NODE_ID)
+               return;
+
+       /* Determine the implicit tag. */
+
        if (s == NULL) {
                if (n->child == NULL || n->child->type != ROFFT_TEXT)
                        return;
@@ -148,7 +161,7 @@ tag_put(const char *s, int prio, struct roff_node *n)
         */
 
        else if (entry->prio < prio)
-                       return;
+               return;
 
        /*
         * If the existing entry is worse, clear it.