diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2022-04-26 11:38:38 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2022-04-26 11:38:38 +0000 |
commit | 008fe3ecbf933d6e4c5edd9fd1ff2327703d428f (patch) | |
tree | 433b10b8a8a24e76f8a06ab36a7cba89d227ddae /tag.c | |
parent | 83f2e011a49d87a26454dc2158dbfb8c5ff24925 (diff) | |
download | mandoc-008fe3ecbf933d6e4c5edd9fd1ff2327703d428f.tar.gz |
If a node is tagged explicitly, skip implicit tagging for that node.
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).
Diffstat (limited to 'tag.c')
-rw-r--r-- | tag.c | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -1,6 +1,7 @@ /* $Id$ */ /* - * 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 @@ -80,7 +81,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) @@ -93,6 +94,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; @@ -150,7 +163,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. |