re PR libfortran/17143 (2**63 prints garbage)
authorBud Davis <bdavis9659@comcast.net>
Wed, 25 Aug 2004 00:31:33 +0000 (00:31 +0000)
committerBud Davis <bdavis@gcc.gnu.org>
Wed, 25 Aug 2004 00:31:33 +0000 (00:31 +0000)
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.

        * gfortran.dg/pr17143.f90: New test.

From-SVN: r86532

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr17143.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/runtime/error.c

index ba023348e2bfa86eb5e0be70b9623758ada8fab2..9a442c429404c1ea2fbc7549ab6c56ea6f272089 100644 (file)
@@ -1,3 +1,8 @@
+2004-08-24  Bud Davis  <bdavis9659@comcast.net>
+
+       PR fortran/17143
+       * gfortran.dg/pr17143.f90: New test.
+
 2004-08-24  Bud Davis  <bdavis9659@comcast.net>
 
        PR fortran/17164
diff --git a/gcc/testsuite/gfortran.dg/pr17143.f90 b/gcc/testsuite/gfortran.dg/pr17143.f90
new file mode 100644 (file)
index 0000000..4be4e2b
--- /dev/null
@@ -0,0 +1,16 @@
+! 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
+
index 1cb06dd46b980870a406e5c746452de7367d1752..aff020da047aad9bbef403d221250e24a8c1fe37 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2004-08-24  Bud Davis  <bdavis9659@comcast.net>
 
        PR fortran/17164
index 8cd980dff9a5e65f6a478c4513694cab11ce0616..448ead871c6bff2c287864b240dd8543f5f24d7b 100644 (file)
@@ -117,6 +117,7 @@ itoa (int64_t n)
 {
   int negative;
   char *p;
+  uint64_t t;
 
   if (n == 0)
     {
@@ -126,19 +127,20 @@ itoa (int64_t n)
     }
 
   negative = 0;
+  t = n;
   if (n < 0)
     {
       negative = 1;
-      n = -n;
+      t = -n; /*must use unsigned to protect from overflow*/
     }
 
   p = buffer + sizeof (buffer) - 1;
   *p-- = '\0';
 
-  while (n != 0)
+  while (t != 0)
     {
-      *p-- = '0' + (n % 10);
-      n /= 10;
+      *p-- = '0' + (t % 10);
+      t /= 10;
     }
 
   if (negative)