aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_validate.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2019-06-27 15:07:30 +0000
committerIngo Schwarze <schwarze@openbsd.org>2019-06-27 15:07:30 +0000
commitf59a251232e343851a0737c21d9a75ffca28adea (patch)
treeda31a7c00b735bc2d319c8a9b75962f46cf1a55f /mdoc_validate.c
parentb6723d5f5a8ba2f1931221d8b92823fd4654722f (diff)
downloadmandoc-f59a251232e343851a0737c21d9a75ffca28adea.tar.gz
mandoc-f59a251232e343851a0737c21d9a75ffca28adea.tar.zst
mandoc-f59a251232e343851a0737c21d9a75ffca28adea.zip
Fix mandoc_normdate() and the way it is used.
In the past, it could return NULL but the calling code wasn't prepared to handle that. Make sure it always returns an allocated string. While here, simplify the code by handling the "quick" attribute inside mandoc_normdate() rather than at multiple callsites. Triggered by deraadt@ pointing out that snprintf(3) error handling was incomplete in time2a().
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r--mdoc_validate.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index c409f908..11cdf00b 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.373 2019/03/13 18:29:18 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.374 2019/06/27 15:07:30 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2019 Ingo Schwarze <schwarze@openbsd.org>
@@ -1903,8 +1903,7 @@ post_root(POST_ARGS)
/* Add missing prologue data. */
if (mdoc->meta.date == NULL)
- mdoc->meta.date = mdoc->quick ? mandoc_strdup("") :
- mandoc_normdate(mdoc, NULL, 0, 0);
+ mdoc->meta.date = mandoc_normdate(mdoc, NULL, 0, 0);
if (mdoc->meta.title == NULL) {
mandoc_msg(MANDOCERR_DT_NOTITLE, 0, 0, "EOF");
@@ -2519,21 +2518,10 @@ post_dd(POST_ARGS)
mandoc_msg(MANDOCERR_PROLOG_ORDER,
n->line, n->pos, "Dd after Os");
- if (n->child == NULL || n->child->string[0] == '\0') {
- mdoc->meta.date = mdoc->quick ? mandoc_strdup("") :
- mandoc_normdate(mdoc, NULL, n->line, n->pos);
- return;
- }
-
datestr = NULL;
deroff(&datestr, n);
- if (mdoc->quick)
- mdoc->meta.date = datestr;
- else {
- mdoc->meta.date = mandoc_normdate(mdoc,
- datestr, n->line, n->pos);
- free(datestr);
- }
+ mdoc->meta.date = mandoc_normdate(mdoc, datestr, n->line, n->pos);
+ free(datestr);
}
static void