re PR libfortran/17143 (2**63 prints garbage)

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
This commit is contained in:
Bud Davis 2004-08-25 00:31:33 +00:00 committed by Bud Davis
parent 0d9f6a32e7
commit 5352bda03e
4 changed files with 33 additions and 4 deletions

View 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

View File

@ -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

View 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

View 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)