This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

[PATCH] libgfortran format conversion bug (PR libgfortran/22412)


	The libgfortran I/O functions otoa() and btoa() use a buffer
`scratch'.  The pointer into the buffer is initialized in those two
functions as

	  p = scratch + sizeof (SCRATCH_SIZE) - 1;

The sizeof (SCRATCH_SIZE) appears to be a thinko, which caused the pointer
to start near the beginning of the buffer instead of near the end, and
conversions of large values would scribble over whatever was allocated
adjacent to the buffer.

Okay for mainline and 4.0?

Thanks, David


	* io/write.c (otoa): Bias p by SCRATCH_SIZE, not
	sizeof (SCRATCH_SIZE).
	(btoa): Same.

Index: write.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/write.c,v
retrieving revision 1.40
diff -c -p -r1.40 write.c
*** write.c	9 Jul 2005 09:33:23 -0000	1.40
--- write.c	11 Jul 2005 22:10:44 -0000
*************** otoa (GFC_UINTEGER_LARGEST n)
*** 1004,1016 ****
        return scratch;
      }
  
!   p = scratch + sizeof (SCRATCH_SIZE) - 1;
    *p-- = '\0';
  
    while (n != 0)
      {
        *p = '0' + (n & 7);
!       p -- ;
        n >>= 3;
      }
  
--- 1004,1016 ----
        return scratch;
      }
  
!   p = scratch + SCRATCH_SIZE - 1;
    *p-- = '\0';
  
    while (n != 0)
      {
        *p = '0' + (n & 7);
!       p--;
        n >>= 3;
      }
  
*************** btoa (GFC_UINTEGER_LARGEST n)
*** 1032,1038 ****
        return scratch;
      }
  
!   p = scratch + sizeof (SCRATCH_SIZE) - 1;
    *p-- = '\0';
  
    while (n != 0)
--- 1032,1038 ----
        return scratch;
      }
  
!   p = scratch + SCRATCH_SIZE - 1;
    *p-- = '\0';
  
    while (n != 0)


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