This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[3.3/mainline;libiberty] Fix vasprintf.c


Hello,

this patch fixes vasprintf.c. The problem was that on some architectures
(x86-64 and ppc64) va_list is not a pointer but an array.

Tested on x86-64, ppc32, ppc64, ia32, ia64, alpha, sparc32, sparc64
(vasprintf.c contains a test enabled by -DTEST)
Bootstrapped/regtested x86=64.

OK for mainline and 3.3 branch?

Josef

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/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	2 Oct 2003 20:07:33 -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)
*** 140,146 ****
  #endif
    *result = (char *) malloc (total_width);
    if (*result != NULL)
!     return vsprintf (*result, format, *args);
    else
      return -1;
  }
--- 144,150 ----
  #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
--- 159,165 ----
       va_list args;
  #endif
  {
!   return int_vasprintf (result, format, args);
  }
  
  #ifdef TEST


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]