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]

[gfortran] patch for pr 17143, output of 2**63 is wrong


tested i686/gnu/linux FC1.

 

--bud


! pr17143
! does not print 2*63 correctly
       character*25 l
       integer*8 i
       data i /1/
       do j = 1,63
          i = i * 2
       end do
       write(l,*)i
       if (l.ne.' -9223372036854775808') then
!                ^
!         the space is required before a number
          call abort
       endif 
       end




2004-08-24  Bud Davis  <bdavis9659@comcast.net>

	PR fortran/17143	
	* runtime/error.c (itoa): keep from overflowing during
        mod operation by using unsigned variable.

Index: gcc/libgfortran/runtime/error.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/runtime/error.c,v
retrieving revision 1.2
diff -c -3 -p -r1.2 error.c
*** gcc/libgfortran/runtime/error.c	13 May 2004 06:41:03 -0000	1.2
--- gcc/libgfortran/runtime/error.c	24 Aug 2004 02:58:58 -0000
*************** itoa (int64_t n)
*** 117,122 ****
--- 117,123 ----
  {
    int negative;
    char *p;
+   uint64_t t;
  
    if (n == 0)
      {
*************** itoa (int64_t n)
*** 126,144 ****
      }
  
    negative = 0;
    if (n < 0)
      {
        negative = 1;
!       n = -n;
      }
  
    p = buffer + sizeof (buffer) - 1;
    *p-- = '\0';
  
!   while (n != 0)
      {
!       *p-- = '0' + (n % 10);
!       n /= 10;
      }
  
    if (negative)
--- 127,146 ----
      }
  
    negative = 0;
+   t = n;
    if (n < 0)
      {
        negative = 1;
!       t = -n; /*must use unsigned to protect from overflow*/
      }
  
    p = buffer + sizeof (buffer) - 1;
    *p-- = '\0';
  
!   while (t != 0)
      {
!       *p-- = '0' + (t % 10);
!       t /= 10;
      }
  
    if (negative)


	


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