From 8c8298198d4578f2d09c34f5b09dea2af3a45a19 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Tue, 26 Apr 2022 11:38:38 +0000 Subject: 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). --- tag.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'tag.c') diff --git a/tag.c b/tag.c index fcaad99f..4e1a32dc 100644 --- a/tag.c +++ b/tag.c @@ -1,6 +1,7 @@ -/* $Id: tag.c,v 1.36 2020/04/19 16:36:16 schwarze Exp $ */ +/* $Id: tag.c,v 1.37 2022/04/26 11:38:38 schwarze Exp $ */ /* - * Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze + * Copyright (c) 2015, 2016, 2018, 2019, 2020, 2022 + * Ingo Schwarze * * 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. -- cgit v1.2.3