From 26db1945888a4c85d55c3c5c75beb49e09c19588 Mon Sep 17 00:00:00 2001 From: shishir gowda Date: Fri, 12 Nov 2010 04:15:08 +0000 Subject: Solaris: vasprint fix for %llu crash vasprint now inturn call gf_vasprintf, which calls vsnprintf. vsnprintf allocates buffer of required size, and hence prevents the sigsegv seen in vasprintf w.r.t %llu Signed-off-by: shishir gowda Signed-off-by: Anand V. Avati BUG: 1058 (vasprintf dumps core when %llu is involved) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1058 --- libglusterfs/src/compat.c | 88 +---------------------------------------------- 1 file changed, 1 insertion(+), 87 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/compat.c b/libglusterfs/src/compat.c index 081869e4b..210221631 100644 --- a/libglusterfs/src/compat.c +++ b/libglusterfs/src/compat.c @@ -311,93 +311,7 @@ char* strsep(char** str, const char* delims) int vasprintf (char **result, const char *format, va_list args) { - const char *p = format; - /* Add one to make sure that it is never zero, which might cause malloc - to return NULL. */ - int total_width = strlen (format) + 1; - va_list ap; - - /* vasprintf does not work on Solaris when memcpy is called on va_list pointers. - * Replacing it with va_copy which works on Solaris - */ - va_copy (ap, args); - - while (*p != '\0') - { - if (*p++ == '%') - { - while (strchr ("-+ #0", *p)) - ++p; - if (*p == '*') - { - ++p; - total_width += abs (va_arg (ap, int)); - } - else - { - char *endp; - total_width += strtoul (p, &endp, 10); - p = endp; - } - if (*p == '.') - { - ++p; - if (*p == '*') - { - ++p; - total_width += abs (va_arg (ap, int)); - } - else - { - char *endp; - total_width += strtoul (p, &endp, 10); - p = endp; - } - } - while (strchr ("hlL", *p)) - ++p; - /* Should be big enough for any format specifier except %s - and floats. */ - total_width += 30; - switch (*p) - { - case 'd': - case 'i': - case 'o': - case 'u': - case 'x': - case 'X': - case 'c': - (void) va_arg (ap, int); - break; - case 'f': - case 'e': - case 'E': - case 'g': - case 'G': - (void) va_arg (ap, double); - /* Since an ieee double can have an exponent of 307, we'll - make the buffer wide enough to cover the gross case. */ - total_width += 307; - - case 's': - total_width += strlen (va_arg (ap, char *)); - break; - case 'p': - case 'n': - (void) va_arg (ap, char *); - break; - } - } - } - - va_end (ap); - - *result = malloc (total_width); - if (*result != NULL) - return vsprintf (*result, format, args); - else - return 0; + return gf_vasprintf(result, format, args); } int -- cgit