diff options
author | Simon Josefsson <simon@josefsson.org> | 2004-10-12 13:26:28 +0000 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2004-10-12 13:26:28 +0000 |
commit | 945c7da4f6af976e4317c616b31118871d8f3709 (patch) | |
tree | 6a7e811df445081b3ec79506e9499dcf760a6d5d /gl/snprintf.c | |
parent | 0888b47113aaffbc5955e66c5363affa930fca35 (diff) | |
download | gnutls-945c7da4f6af976e4317c616b31118871d8f3709.tar.gz |
Update gnulib.
Diffstat (limited to 'gl/snprintf.c')
-rw-r--r-- | gl/snprintf.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/gl/snprintf.c b/gl/snprintf.c index 667ed94625..9a4edc1f5f 100644 --- a/gl/snprintf.c +++ b/gl/snprintf.c @@ -42,19 +42,19 @@ snprintf (char *str, size_t size, const char *format, ...) va_list args; va_start (args, format); - output = vasnprintf (NULL, &len, format, args); + len = size; + output = vasnprintf (str, &len, format, args); va_end (args); if (!output) return -1; - if (str && size > 0) - { - memcpy (str, output, MIN (len + 1, size)); + if (str != NULL) + if (len > size - 1) /* equivalent to: (size > 0 && len >= size) */ str[size - 1] = '\0'; - } - free (output); + if (output != str) + free (output); return len; } |