summaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authorBud Davis <bdavis9659@comcast.net>2004-08-25 00:31:33 +0000
committerBud Davis <bdavis@gcc.gnu.org>2004-08-25 00:31:33 +0000
commit5352bda03ee91af3e4592d0f62178fae15daab40 (patch)
tree8fea482f4eead23b6036f3b25416d71571d83c8c /libgfortran
parent0d9f6a32e752c86c85053d46262e9bf901399a68 (diff)
downloadgcc-5352bda03ee91af3e4592d0f62178fae15daab40.tar.gz
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')
-rw-r--r--libgfortran/ChangeLog6
-rw-r--r--libgfortran/runtime/error.c10
2 files changed, 12 insertions, 4 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 1cb06dd46b9..aff020da047 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,5 +1,11 @@
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
* runtime/string_intrinsics.c (string_index):check for
substring longer than string.
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)