From: Guus Sliepen Date: Wed, 17 Jul 2013 16:08:58 +0000 (+0200) Subject: Don't use vasprintf() anymore on Windows. X-Git-Tag: release-1.0.22~3 X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=commitdiff_plain;h=cfa738d3185980ff8532a35192a9113b0e9a937c Don't use vasprintf() anymore on Windows. Windows doesn't actually support it, but MinGW provides it. However, with some versions of MinGW it doesn't work correctly. Instead, we vsnprintf() to a local buffer and xstrdup() the results. --- diff --git a/lib/xmalloc.c b/lib/xmalloc.c index e4079ce4..58f2bcee 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -147,10 +147,18 @@ int xasprintf(char **strp, const char *fmt, ...) { } int xvasprintf(char **strp, const char *fmt, va_list ap) { +#ifdef HAVE_MINGW + char buf[1024]; + int result = vsnprintf(buf, sizeof buf, fmt, ap); + if(result < 0) + exit(xalloc_exit_failure); + *strp = xstrdup(buf); +#else int result = vasprintf(strp, fmt, ap); if(result < 0) { fprintf(stderr, "vasprintf() failed: %s\n", strerror(errno)); exit(xalloc_exit_failure); } +#endif return result; }