From: Bruno Haible Date: Fri, 1 Oct 2004 10:26:52 +0000 (+0000) Subject: Fixes, mostly from Simon Josefsson. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=edafda534244e3760000faf7a088af872d146325;p=pspp Fixes, mostly from Simon Josefsson. --- diff --git a/lib/ChangeLog b/lib/ChangeLog index f92f90831d..a701b151fb 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,6 +1,8 @@ -2004-10-01 Bruno Haible +2004-10-01 Simon Josefsson + Bruno Haible - * snprintf.c: Include . + * snprintf.c: Include , , . + (snprintf): Declare 'args'. 2004-09-30 Simon Josefsson diff --git a/lib/snprintf.c b/lib/snprintf.c index 417dd33e19..92c265289a 100644 --- a/lib/snprintf.c +++ b/lib/snprintf.c @@ -20,10 +20,14 @@ # include #endif -/* Get specification. */ +/* Specification. */ #include "snprintf.h" -/* Get memcpy. */ +/* Get va_list, va_start, va_end. */ +#include +/* Get free. */ +#include +/* Get memcpy, size_t. */ #include /* Get vasnprintf. */ @@ -40,19 +44,24 @@ int snprintf (char *str, size_t size, const char *format, ...) { + char *output; size_t len; - char *out = vasnprintf (NULL, &len, format, args); + va_list args; - if (!out) + va_start (args, format); + output = vasnprintf (NULL, &len, format, args); + va_end (args); + + if (!output) return -1; if (str) { - memcpy (str, out, MIN (len + 1, size)); + memcpy (str, output, MIN (len + 1, size)); str[size - 1] = '\0'; } - free (out); + free (output); return len; }