From: Christian Neukirchen <chneukirchen@gmail.com>
To: tech@mdocml.bsd.lv
Subject: compat_vasprintf.c: use va_copy
Date: Fri, 20 Mar 2015 15:36:49 +0100 [thread overview]
Message-ID: <87vbhv7n26.fsf@gmail.com> (raw)
Hi,
When building CVS HEAD on Linux x86_64/glibc, the vasprintf check
fails when -D_GNU_SOURCE is not passed, and mdocml falls back to
compat_vasprintf.c. This version of vasprintf.c segfaults on glibc,
because the same va_list is used twice. Probably affects other
architectures too.
The solution is to use va_copy to get a second va_list.
--- compat_vasprintf.c
+++ compat_vasprintf.c
@@ -38,9 +38,13 @@ vasprintf(char **ret, const char *format, va_list ap)
{
char buf[2];
int sz;
+ va_list ap2;
- if ((sz = vsnprintf(buf, sizeof(buf), format, ap)) != -1 &&
- (*ret = malloc(sz + 1)) != NULL) {
+ va_copy(ap2, ap);
+ sz = vsnprintf(buf, sizeof(buf), format, ap2);
+ va_end(ap2);
+
+ if (sz != -1 && (*ret = malloc(sz + 1)) != NULL) {
if (vsnprintf(*ret, sz + 1, format, ap) == sz)
return(sz);
free(*ret);
cu,
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv
next reply other threads:[~2015-03-20 14:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-20 14:36 Christian Neukirchen [this message]
2015-03-20 15:45 ` Ingo Schwarze
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=87vbhv7n26.fsf@gmail.com \
--to=chneukirchen@gmail.com \
--cc=tech@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).