Fix crash on numeric comparison again (ref #2825)

The decNumber library subtracts the exponents of two numbers,
we make sure to limit the number of digits not to make it overflows.
Since the maximum adjusted exponent is `emax` and the minimum is
`emin - digits + 1`, we follow `emax - (emin - digits + 1) <= INT32_MAX`.
This commit is contained in:
itchyny authored and Emanuele Torre committed 2023-08-13 14:17:25 +02:00
1 parent f86566b263
commit 3fa10e8cc1
2 files changed
+18 -2

No files matched your search

+1 -1
View File
@@ -528,7 +528,7 @@ static decContext* tsd_dec_ctx_get(pthread_key_t *key) {
if (key == &dec_ctx_key)
{
decContextDefault(ctx, DEC_INIT_BASE);
ctx->digits = DEC_MAX_DIGITS - 1;
ctx->digits = INT32_MAX - (ctx->emax - ctx->emin - 1);
ctx->traps = 0; /*no errors*/
}
else if (key == &dec_ctx_dbl_key)