Commit 6ddb1bc1 by Graham Stott Committed by Graham Stott

real.c (real_to_decimal): Fix buffer overrun when buffer size is smaller than representation.


        * real.c (real_to_decimal): Fix buffer overrun when buffer size
        is smaller than representation.

From-SVN: r59200
parent b9ad851e
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> 2002-11-17 Kazu Hirata <kazu@cs.umass.edu>
* builtins.c: Fix formatting. * builtins.c: Fix formatting.
......
...@@ -1485,6 +1485,11 @@ real_to_decimal (str, r_orig, buf_size, digits, crop_trailing_zeros) ...@@ -1485,6 +1485,11 @@ real_to_decimal (str, r_orig, buf_size, digits, crop_trailing_zeros)
abort (); 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 /* Estimate the decimal exponent, and compute the length of the string it
will print as. Be conservative and add one to account for possible will print as. Be conservative and add one to account for possible
overflow or rounding error. */ overflow or rounding error. */
...@@ -1499,11 +1504,6 @@ real_to_decimal (str, r_orig, buf_size, digits, crop_trailing_zeros) ...@@ -1499,11 +1504,6 @@ real_to_decimal (str, r_orig, buf_size, digits, crop_trailing_zeros)
if (digits > max_digits) if (digits > max_digits)
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); one = real_digit (1);
ten = ten_to_ptwo (0); ten = ten_to_ptwo (0);
......
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