diff options
author | Graham Stott <graham.stott@btinternet.com> | 2002-11-17 20:20:39 +0000 |
---|---|---|
committer | Graham Stott <grahams@gcc.gnu.org> | 2002-11-17 20:20:39 +0000 |
commit | 6ddb1bc19f3860740acc0ed31e54ab8cfac07dd2 (patch) | |
tree | e4264e6f20aa6cc6f9fcc388cc0d093fc3401ab4 /gcc | |
parent | b9ad851eef2923e08c8e3521fd1e48322b2189ee (diff) | |
download | gcc-6ddb1bc19f3860740acc0ed31e54ab8cfac07dd2.zip gcc-6ddb1bc19f3860740acc0ed31e54ab8cfac07dd2.tar.gz gcc-6ddb1bc19f3860740acc0ed31e54ab8cfac07dd2.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/real.c | 10 |
2 files changed, 10 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bc2c88b..6434f60 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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. @@ -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); |