From e89dd22a4fc303f8cdf4180c4fb9655a45e8e724 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Thu, 12 Feb 2015 12:24:33 +0000 Subject: Delete the mdoc_node.pending pointer and the function calculating it, make_pending(), which was the most difficult function of the whole mdoc(7) parser. After almost five years of maintaining this hellhole, i just noticed the pointer isn't needed after all. Blocks are always rewound in the reverse order they were opened; that even holds for broken blocks. Consequently, it is sufficient to just mark broken blogs with the flag MDOC_BROKEN and breaking blocks with the flag MDOC_ENDED. When rewinding, instead of iterating the pending pointers, just iterate from each broken block to its parents, rewinding all that are MDOC_ENDED and stopping after processing the first ancestor that it not MDOC_BROKEN. For ENDBODY markers, use the mdoc_node.body pointer in place of the former mdoc_node.pending. This also fixes an assertion failure found by jsg@ with afl, test case #467 (Bo Bl It Bd Bc It), where (surprise surprise) the pending pointer got corrupted. Improved functionality, minus one function, minus one struct field, minus 50 lines of code. --- mdoc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'mdoc.c') diff --git a/mdoc.c b/mdoc.c index 6bb3d445..92960a2f 100644 --- a/mdoc.c +++ b/mdoc.c @@ -1,7 +1,7 @@ -/* $Id: mdoc.c,v 1.236 2015/02/05 00:14:13 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.237 2015/02/12 12:24:33 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze + * Copyright (c) 2010, 2012-2015 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 @@ -419,8 +419,10 @@ mdoc_endbody_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok, { struct mdoc_node *p; + body->flags |= MDOC_ENDED; + body->parent->flags |= MDOC_ENDED; p = node_alloc(mdoc, line, pos, tok, MDOC_BODY); - p->pending = body; + p->body = body; p->norm = body->norm; p->end = end; node_append(mdoc, p); -- cgit v1.2.3-56-ge451