Fix overflow on numeric comparison (#2849)
Although #2839 fixed the overflow of exponent subtraction, there still is possibility of overflow in the `D2U` macro. This patch fixes the overflow in the `D2U` macro, and also truncates the maximum digits to `DEC_MAX_DIGITS`.
This commit is contained in:
1 parent
0733fd3d58
commit
7d64381016
2 files changed
+4
-2
No files matched your search
@@ -528,7 +528,9 @@ static decContext* tsd_dec_ctx_get(pthread_key_t *key) {
|
|||||||
if (key == &dec_ctx_key)
|
if (key == &dec_ctx_key)
|
||||||
{
|
{
|
||||||
decContextDefault(ctx, DEC_INIT_BASE);
|
decContextDefault(ctx, DEC_INIT_BASE);
|
||||||
ctx->digits = INT32_MAX - (ctx->emax - ctx->emin - 1);
|
// make sure (Int)D2U(rhs->exponent-lhs->exponent) does not overflow
|
||||||
|
ctx->digits = MIN(DEC_MAX_DIGITS,
|
||||||
|
INT32_MAX - (DECDPUN - 1) - (ctx->emax - ctx->emin - 1));
|
||||||
ctx->traps = 0; /*no errors*/
|
ctx->traps = 0; /*no errors*/
|
||||||
}
|
}
|
||||||
else if (key == &dec_ctx_dbl_key)
|
else if (key == &dec_ctx_dbl_key)
|
||||||
|
|||||||
+1
-1
@@ -569,7 +569,7 @@ true
|
|||||||
true
|
true
|
||||||
|
|
||||||
# #2825
|
# #2825
|
||||||
(1e999999999, 10e999999999) > (1e-1147483648, 0.1e-1147483648)
|
(1e999999999, 10e999999999) > (1e-1147483646, 0.1e-1147483646)
|
||||||
null
|
null
|
||||||
true
|
true
|
||||||
true
|
true
|
||||||
|
|||||||
Reference in new issue
Block a user