From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: strlen+malloc+snprintf is error prone; rewrite post_lb() to use
Date: Sun, 20 Apr 2014 16:48:53 -0400 (EDT) [thread overview]
Message-ID: <201404202048.s3KKmrE2002624@krisdoz.my.domain> (raw)
Log Message:
-----------
strlen+malloc+snprintf is error prone;
rewrite post_lb() to use asprintf(3) instead
Modified Files:
--------------
mdocml:
mdoc_validate.c
Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.211
retrieving revision 1.212
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.211 -r1.212
--- mdoc_validate.c
+++ 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);
+ n = mdoc->last->child;
- p = mdoc_a2lib(mdoc->last->child->string);
+ assert(n);
+ assert(MDOC_TEXT == n->type);
- /* If lookup ok, replace with table value. */
+ if (NULL == (stdlibname = mdoc_a2lib(n->string)))
+ mandoc_asprintf(&libname,
+ "library \\(lq%s\\(rq", n->string);
+ else
+ libname = mandoc_strdup(stdlibname);
- if (p) {
- free(mdoc->last->child->string);
- mdoc->last->child->string = mandoc_strdup(p);
- return(1);
- }
-
- /* If not, use "library ``xxxx''. */
-
- 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);
}
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2014-04-20 20:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201404202048.s3KKmrE2002624@krisdoz.my.domain \
--to=schwarze@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).