This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [3.3/mainline;libiberty] Fix vasprintf.c
> The matching va_end for va_copy is missing. Every va_copy must be paired
> with a call to va_end, just like va_start.
>
> Andreas.
Here is the updated patch.
2003-10-03 Josef Zlomek <zlomekj@suse.cz>
Jan Hubicka <jh@suse.cz>
* vasprintf.c (int_vasprintf): Pass va_list by value.
Use va_copy for copying va_list.
(vasprintf): Pass va_list by value.
Index: vasprintf.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/libiberty/vasprintf.c,v
retrieving revision 1.12
diff -c -3 -p -r1.12 vasprintf.c
*** vasprintf.c 3 Jun 2003 18:19:17 -0000 1.12
--- vasprintf.c 3 Oct 2003 16:44:37 -0000
*************** not be allocated, minus one is returned
*** 59,71 ****
*/
! static int int_vasprintf PARAMS ((char **, const char *, va_list *));
static int
int_vasprintf (result, format, args)
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
--- 59,71 ----
*/
! static int int_vasprintf PARAMS ((char **, const char *, va_list));
static int
int_vasprintf (result, format, args)
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
*************** int_vasprintf (result, format, args)
*** 73,79 ****
int total_width = strlen (format) + 1;
va_list ap;
! memcpy ((PTR) &ap, (PTR) args, sizeof (va_list));
while (*p != '\0')
{
--- 73,83 ----
int total_width = strlen (format) + 1;
va_list ap;
! #ifdef va_copy
! va_copy (ap, args);
! #else
! memcpy ((PTR) &ap, (PTR) &args, sizeof (va_list));
! #endif
while (*p != '\0')
{
*************** int_vasprintf (result, format, args)
*** 135,146 ****
p++;
}
}
#ifdef TEST
global_total_width = total_width;
#endif
*result = (char *) malloc (total_width);
if (*result != NULL)
! return vsprintf (*result, format, *args);
else
return -1;
}
--- 139,153 ----
p++;
}
}
+ #ifdef va_copy
+ va_end (ap);
+ #endif
#ifdef TEST
global_total_width = total_width;
#endif
*result = (char *) malloc (total_width);
if (*result != NULL)
! return vsprintf (*result, format, args);
else
return -1;
}
*************** vasprintf (result, format, args)
*** 155,161 ****
va_list args;
#endif
{
! return int_vasprintf (result, format, &args);
}
#ifdef TEST
--- 162,168 ----
va_list args;
#endif
{
! return int_vasprintf (result, format, args);
}
#ifdef TEST