diff options
author | shishir gowda <shishirng@gluster.com> | 2010-11-12 04:15:08 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-11-13 07:02:27 -0800 |
commit | 26db1945888a4c85d55c3c5c75beb49e09c19588 (patch) | |
tree | be371ebb27237fddb90e6441b944d73b4ed3440b /libglusterfs/src/compat.c | |
parent | 0bd8ecda6554e20336112febf1ade9e1d66bea8e (diff) |
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 <shishirng@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 1058 (vasprintf dumps core when %llu is involved)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1058
Diffstat (limited to 'libglusterfs/src/compat.c')
-rw-r--r-- | libglusterfs/src/compat.c | 88 |
1 files changed, 1 insertions, 87 deletions
diff --git a/libglusterfs/src/compat.c b/libglusterfs/src/compat.c index 081869e4b0f..2102216317d 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 |