diff options
author | Hib Eris <hib@hiberis.nl> | 2010-02-02 11:13:53 +0100 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2010-02-03 12:47:57 +0100 |
commit | a03d49102e2d83b1ee008296da426b67e5585302 (patch) | |
tree | e7f7d6de2ba894128d410e70fa9b64b715bd39bc | |
parent | 5f261f571d1cd6bbd6dd12ca5eacb0edc79ebc06 (diff) |
Use _vscprintf instead of vsnprintf when available
On Windows, if output was truncated, vsnprintf() does not return
the number of characters which would have been written to the string
if enough space had been available.
To work around this, use _vcsprintf() instead.
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | libspectre/spectre-utils.c | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 1982e37..5189b20 100644 --- a/configure.ac +++ b/configure.ac @@ -59,6 +59,8 @@ AC_C_BIGENDIAN AC_CHECK_FUNC(vasprintf, [ AC_DEFINE(HAVE_VASPRINTF, 1, [Define if the 'vasprintf' function is available.]) ]) +AC_CHECK_FUNC(_vscprintf, [ AC_DEFINE(HAVE__VSCPRINTF, 1, [Define if the '_vscprintf' function is available.]) ]) + LIBGS_REQUIRED="8.62" AC_CHECK_LIB(gs, gsapi_new_instance, have_libgs=yes, have_libgs=no) diff --git a/libspectre/spectre-utils.c b/libspectre/spectre-utils.c index 0d8cf02..d88bef9 100644 --- a/libspectre/spectre-utils.c +++ b/libspectre/spectre-utils.c @@ -162,11 +162,17 @@ spectre_strdup_vprintf (const char *format, string = NULL; #else /* !HAVE_VASPRINTF */ va_list args_copy; + int n; char c; SPECTRE_VA_COPY (args_copy, args); - string = malloc ((vsnprintf (&c, 1, format, args) + 1) * sizeof (char)); +#if HAVE__VSCPRINTF + n = _vscprintf (format, args); +#else + n = vsnprintf (&c, 1, format, args); +#endif + string = malloc ((n + 1) * sizeof (char)); if (string) { len = vsprintf (string, format, args_copy); if (len < 0) { |