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]

Re: Patch for libgfortran PR 18891


This is a replacement patch for my earlier patch to fix PR 18891.
I found another place in transfer.c (us_read) where we were accessing
unaligned memory and fixed that the same way I fixed us_write and
next_record_w.  I also changed some of my memcpy calls to use an
existing variable as the length of the memcpy instead of sizeof()
because the variable in question was set based on sizeof() earlier in
the routine.

Tested on ia64-hp-hpux11.23 with no regressions.

OK for checkin?

2004-12-10  Steve Ellcey  <sje@cup.hp.com>

	* libgfortran/io/transfer.c (us_read): Use memcpy instead 
	of assignment to fill unaligned buffer.
	(us_write): Ditto.
	(next_record_w): Ditto.


*** gcc.orig/libgfortran/io/transfer.c	Fri Dec 10 08:57:51 2004
--- gcc/libgfortran/io/transfer.c	Fri Dec 10 16:33:26 2004
*************** transfer_complex (void *p, int kind)
*** 819,829 ****
  static void
  us_read (void)
  {
!   gfc_offset *p;
    int n;
  
    n = sizeof (gfc_offset);
!   p = (gfc_offset *) salloc_r (current_unit->s, &n);
  
    if (p == NULL || n != sizeof (gfc_offset))
      {
--- 819,830 ----
  static void
  us_read (void)
  {
!   char *p;
    int n;
+   gfc_offset i;
  
    n = sizeof (gfc_offset);
!   p = salloc_r (current_unit->s, &n);
  
    if (p == NULL || n != sizeof (gfc_offset))
      {
*************** us_read (void)
*** 831,837 ****
        return;
      }
  
!   current_unit->bytes_left = *p;
  }
  
  
--- 832,839 ----
        return;
      }
  
!   memcpy (&i, p, n);
!   current_unit->bytes_left = i;
  }
  
  
*************** us_read (void)
*** 841,851 ****
  static void
  us_write (void)
  {
!   gfc_offset *p;
    int length;
  
    length = sizeof (gfc_offset);
!   p = (gfc_offset *) salloc_w (current_unit->s, &length);
  
    if (p == NULL)
      {
--- 843,854 ----
  static void
  us_write (void)
  {
!   char *p;
!   gfc_offset zero = 0;
    int length;
  
    length = sizeof (gfc_offset);
!   p = salloc_w (current_unit->s, &length);
  
    if (p == NULL)
      {
*************** us_write (void)
*** 853,859 ****
        return;
      }
  
!   *p = 0;			/* Bogus value for now.  */
    if (sfree (current_unit->s) == FAILURE)
      generate_error (ERROR_OS, NULL);
  
--- 856,862 ----
        return;
      }
  
!   memcpy (p, &zero, length);	/* Bogus value for now.  */
    if (sfree (current_unit->s) == FAILURE)
      generate_error (ERROR_OS, NULL);
  
*************** next_record_w (int done)
*** 1281,1287 ****
        if (p == NULL)
  	goto io_error;
  
!       *((gfc_offset *) p) = m;
        if (sfree (current_unit->s) == FAILURE)
  	goto io_error;
  
--- 1284,1290 ----
        if (p == NULL)
  	goto io_error;
  
!       memcpy (p, &m, length);
        if (sfree (current_unit->s) == FAILURE)
  	goto io_error;
  
*************** next_record_w (int done)
*** 1292,1298 ****
        if (p == NULL)
  	generate_error (ERROR_OS, NULL);
  
!       *((gfc_offset *) p) = m;
        if (sfree (current_unit->s) == FAILURE)
  	goto io_error;
  
--- 1295,1301 ----
        if (p == NULL)
  	generate_error (ERROR_OS, NULL);
  
!       memcpy (p, &m, length);
        if (sfree (current_unit->s) == FAILURE)
  	goto io_error;
  


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