From 5352bda03ee91af3e4592d0f62178fae15daab40 Mon Sep 17 00:00:00 2001 From: Bud Davis Date: Wed, 25 Aug 2004 00:31:33 +0000 Subject: [PATCH] re PR libfortran/17143 (2**63 prints garbage) 2004-08-24 Bud Davis 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 | 5 +++++ gcc/testsuite/gfortran.dg/pr17143.f90 | 16 ++++++++++++++++ libgfortran/ChangeLog | 6 ++++++ libgfortran/runtime/error.c | 10 ++++++---- 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr17143.f90 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ba023348e2b..9a442c42940 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-08-24 Bud Davis + + PR fortran/17143 + * gfortran.dg/pr17143.f90: New test. + 2004-08-24 Bud Davis PR fortran/17164 diff --git a/gcc/testsuite/gfortran.dg/pr17143.f90 b/gcc/testsuite/gfortran.dg/pr17143.f90 new file mode 100644 index 00000000000..4be4e2b92b9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr17143.f90 @@ -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 + diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 1cb06dd46b9..aff020da047 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2004-08-24 Bud Davis + + PR fortran/17143 + * runtime/error.c (itoa): keep from overflowing during + mod operation by using unsigned variable. + 2004-08-24 Bud Davis PR fortran/17164 diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c index 8cd980dff9a..448ead871c6 100644 --- a/libgfortran/runtime/error.c +++ b/libgfortran/runtime/error.c @@ -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) -- 2.30.2