real.c (real_to_decimal): Fix buffer overrun when buffer size is smaller than represe...
authorGraham Stott <graham.stott@btinternet.com>
Sun, 17 Nov 2002 20:20:39 +0000 (20:20 +0000)
committerGraham Stott <grahams@gcc.gnu.org>
Sun, 17 Nov 2002 20:20:39 +0000 (20:20 +0000)
        * real.c (real_to_decimal): Fix buffer overrun when buffer size
        is smaller than representation.

From-SVN: r59200

gcc/ChangeLog
gcc/real.c

index bc2c88b905fa97b90ccfdbe677b41318c9645025..6434f60d1e216a817b5fa31485776ddce0175d1a 100644 (file)
@@ -1,3 +1,8 @@
+2002-11-17  Graham Stott  <graham.stott@btinternet.com>
+
+       * real.c (real_to_decimal): Fix buffer overrun when buffer size
+       is smaller than representation.
+
 2002-11-17  Kazu Hirata  <kazu@cs.umass.edu>
 
        * builtins.c: Fix formatting.
index 3bf46370bbbec172857a460486c722f1374add5c..d9a4b801e3d4e92b445605c5fa5304b67cf3b464 100644 (file)
@@ -1485,6 +1485,11 @@ real_to_decimal (str, r_orig, buf_size, digits, crop_trailing_zeros)
       abort ();
     }
 
+  /* Bound the number of digits printed by the size of the representation.  */
+  max_digits = SIGNIFICAND_BITS * M_LOG10_2;
+  if (digits == 0 || digits > max_digits)
+    digits = max_digits;
+
   /* Estimate the decimal exponent, and compute the length of the string it
      will print as.  Be conservative and add one to account for possible
      overflow or rounding error.  */
@@ -1499,11 +1504,6 @@ real_to_decimal (str, r_orig, buf_size, digits, crop_trailing_zeros)
   if (digits > max_digits)
     digits = max_digits;
 
-  /* Bound the number of digits printed by the size of the representation.  */
-  max_digits = SIGNIFICAND_BITS * M_LOG10_2;
-  if (digits == 0 || digits > max_digits)
-    digits = max_digits;
-
   one = real_digit (1);
   ten = ten_to_ptwo (0);