summaryrefslogtreecommitdiffstats
path: root/mdoc_validate.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-04-20 20:48:53 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-04-20 20:48:53 +0000
commit9836682d8f743fe4f30e9772ea332b04d86dd6d7 (patch)
tree17cd4dfd24ef4897358d93f2eb6eb4f7035c2a31 /mdoc_validate.c
parent0e671b23106993a04ea9629722c1308693db3523 (diff)
downloadmandoc-9836682d8f743fe4f30e9772ea332b04d86dd6d7.tar.gz
strlen+malloc+snprintf is error prone;
rewrite post_lb() to use asprintf(3) instead
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r--mdoc_validate.c35
1 files changed, 13 insertions, 22 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index fb7863ec..0e089f91 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1044,34 +1044,25 @@ post_bf(POST_ARGS)
static int
post_lb(POST_ARGS)
{
- const char *p;
- char *buf;
- size_t sz;
+ struct mdoc_node *n;
+ const char *stdlibname;
+ char *libname;
check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 1);
- assert(mdoc->last->child);
- assert(MDOC_TEXT == mdoc->last->child->type);
-
- p = mdoc_a2lib(mdoc->last->child->string);
-
- /* If lookup ok, replace with table value. */
+ n = mdoc->last->child;
- if (p) {
- free(mdoc->last->child->string);
- mdoc->last->child->string = mandoc_strdup(p);
- return(1);
- }
+ assert(n);
+ assert(MDOC_TEXT == n->type);
- /* If not, use "library ``xxxx''. */
+ if (NULL == (stdlibname = mdoc_a2lib(n->string)))
+ mandoc_asprintf(&libname,
+ "library \\(lq%s\\(rq", n->string);
+ else
+ libname = mandoc_strdup(stdlibname);
- sz = strlen(mdoc->last->child->string) + 2 +
- strlen("\\(lqlibrary\\(rq");
- buf = mandoc_malloc(sz);
- snprintf(buf, sz, "library \\(lq%s\\(rq",
- mdoc->last->child->string);
- free(mdoc->last->child->string);
- mdoc->last->child->string = buf;
+ free(n->string);
+ n->string = libname;
return(1);
}