diff options
| author | John McCall <rjmccall@apple.com> | 2010-02-26 22:20:41 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-02-26 22:20:41 +0000 |
| commit | 0551cd5d7ca6281a77a3318852d26f122f085dd9 (patch) | |
| tree | c60ed1b96cb35c3045511be0ffce77fedbd6048c /lib/Support | |
| parent | 6478712f778316f7b171e3d9f18c500e14cd843a (diff) | |
| download | external_llvm-0551cd5d7ca6281a77a3318852d26f122f085dd9.zip external_llvm-0551cd5d7ca6281a77a3318852d26f122f085dd9.tar.gz external_llvm-0551cd5d7ca6281a77a3318852d26f122f085dd9.tar.bz2 | |
Make APFloat's string-parsing routines a bit safer against very large exponents.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97278 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
| -rw-r--r-- | lib/Support/APFloat.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp index 1e6d22f..f90973f 100644 --- a/lib/Support/APFloat.cpp +++ b/lib/Support/APFloat.cpp @@ -17,6 +17,7 @@ #include "llvm/ADT/FoldingSet.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" +#include <limits.h> #include <cstring> using namespace llvm; @@ -2345,11 +2346,24 @@ APFloat::convertFromDecimalString(const StringRef &str, roundingMode rounding_mo if (decDigitValue(*D.firstSigDigit) >= 10U) { category = fcZero; fs = opOK; - } else if ((D.normalizedExponent + 1) * 28738 - <= 8651 * (semantics->minExponent - (int) semantics->precision)) { + + /* Check whether the normalized exponent is high enough to overflow + max during the log-rebasing in the max-exponent check below. */ + } else if (D.normalizedExponent - 1 > INT_MAX / 42039) { + fs = handleOverflow(rounding_mode); + + /* If it wasn't, then it also wasn't high enough to overflow max + during the log-rebasing in the min-exponent check. Check that it + won't overflow min in either check, then perform the min-exponent + check. */ + } else if (D.normalizedExponent - 1 < INT_MIN / 42039 || + (D.normalizedExponent + 1) * 28738 <= + 8651 * (semantics->minExponent - (int) semantics->precision)) { /* Underflow to zero and round. */ zeroSignificand(); fs = normalize(rounding_mode, lfLessThanHalf); + + /* We can finally safely perform the max-exponent check. */ } else if ((D.normalizedExponent - 1) * 42039 >= 12655 * semantics->maxExponent) { /* Overflow and round. */ |
