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
This commit is contained in:
parent
0bd8ecda65
commit
26db194588
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user