diff options
author | Bud Davis <bdavis9659@comcast.net> | 2004-08-25 00:31:33 +0000 |
---|---|---|
committer | Bud Davis <bdavis@gcc.gnu.org> | 2004-08-25 00:31:33 +0000 |
commit | 5352bda03ee91af3e4592d0f62178fae15daab40 (patch) | |
tree | 8fea482f4eead23b6036f3b25416d71571d83c8c /libgfortran/runtime | |
parent | 0d9f6a32e752c86c85053d46262e9bf901399a68 (diff) | |
download | gcc-5352bda03ee91af3e4592d0f62178fae15daab40.zip gcc-5352bda03ee91af3e4592d0f62178fae15daab40.tar.gz gcc-5352bda03ee91af3e4592d0f62178fae15daab40.tar.bz2 |
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
Diffstat (limited to 'libgfortran/runtime')
-rw-r--r-- | libgfortran/runtime/error.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c index 8cd980d..448ead8 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) |