diff options
author | grahams <grahams@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-11-17 20:20:39 +0000 |
---|---|---|
committer | grahams <grahams@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-11-17 20:20:39 +0000 |
commit | a210f14b5f977c6d7b6339810031b63f112f6cf4 (patch) | |
tree | e4264e6f20aa6cc6f9fcc388cc0d093fc3401ab4 /gcc/real.c | |
parent | e3661df583715205926f8d36baa6b6b6714b1fab (diff) | |
download | gcc-a210f14b5f977c6d7b6339810031b63f112f6cf4.tar.gz |
* real.c (real_to_decimal): Fix buffer overrun when buffer size
is smaller than representation.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@59200 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/real.c')
-rw-r--r-- | gcc/real.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/gcc/real.c b/gcc/real.c index 3bf46370bbb..d9a4b801e3d 100644 --- a/gcc/real.c +++ b/gcc/real.c @@ -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); |