Commit 5352bda0 by Bud Davis Committed by Bud Davis

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
parent 0d9f6a32
2004-08-24 Bud Davis <bdavis9659@comcast.net> 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 PR fortran/17164
* gfortran.dg/pr17164.f90: New test. * gfortran.dg/pr17164.f90: New test.
......
! 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> 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 PR fortran/17164
* runtime/string_intrinsics.c (string_index):check for * runtime/string_intrinsics.c (string_index):check for
substring longer than string. substring longer than string.
......
...@@ -117,6 +117,7 @@ itoa (int64_t n) ...@@ -117,6 +117,7 @@ itoa (int64_t n)
{ {
int negative; int negative;
char *p; char *p;
uint64_t t;
if (n == 0) if (n == 0)
{ {
...@@ -126,19 +127,20 @@ itoa (int64_t n) ...@@ -126,19 +127,20 @@ itoa (int64_t n)
} }
negative = 0; negative = 0;
t = n;
if (n < 0) if (n < 0)
{ {
negative = 1; negative = 1;
n = -n; t = -n; /*must use unsigned to protect from overflow*/
} }
p = buffer + sizeof (buffer) - 1; p = buffer + sizeof (buffer) - 1;
*p-- = '\0'; *p-- = '\0';
while (n != 0) while (t != 0)
{ {
*p-- = '0' + (n % 10); *p-- = '0' + (t % 10);
n /= 10; t /= 10;
} }
if (negative) if (negative)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment