diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2011-01-09 13:16:49 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2011-01-09 13:16:49 +0000 |
commit | 3c9c604a64efed225f768091ed1dd80a5ab79a05 (patch) | |
tree | f594bf2c832ac27c654a7c865cae7141dc407061 /usr.bin/mandoc/mdoc.c | |
parent | 7e15fa387e285cdbcf8ba89627dc992a6c0eee88 (diff) |
Make sure coding errors cannot make us miss fatal parsing errors
by assert(3)ing valid parser state in the main parsing functions;
from kristaps@.
Diffstat (limited to 'usr.bin/mandoc/mdoc.c')
-rw-r--r-- | usr.bin/mandoc/mdoc.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c index 51386a989ab..a6b50af9e83 100644 --- a/usr.bin/mandoc/mdoc.c +++ b/usr.bin/mandoc/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.77 2011/01/04 22:28:17 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.78 2011/01/09 13:16:48 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> @@ -102,7 +102,8 @@ const struct mdoc_node * mdoc_node(const struct mdoc *m) { - return(MDOC_HALT & m->flags ? NULL : m->first); + assert( ! (MDOC_HALT & m->flags)); + return(m->first); } @@ -110,7 +111,8 @@ const struct mdoc_meta * mdoc_meta(const struct mdoc *m) { - return(MDOC_HALT & m->flags ? NULL : &m->meta); + assert( ! (MDOC_HALT & m->flags)); + return(&m->meta); } @@ -211,9 +213,8 @@ int mdoc_endparse(struct mdoc *m) { - if (MDOC_HALT & m->flags) - return(0); - else if (mdoc_macroend(m)) + assert( ! (MDOC_HALT & m->flags)); + if (mdoc_macroend(m)) return(1); m->flags |= MDOC_HALT; return(0); @@ -223,8 +224,7 @@ int mdoc_addspan(struct mdoc *m, const struct tbl_span *sp) { - if (MDOC_HALT & m->flags) - return(0); + assert( ! (MDOC_HALT & m->flags)); /* No text before an initial macro. */ @@ -246,8 +246,7 @@ int mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs) { - if (MDOC_HALT & m->flags) - return(0); + assert( ! (MDOC_HALT & m->flags)); m->flags |= MDOC_NEWLINE; |