diff --git a/src/builtin.c b/src/builtin.c index 793b597666..88378e255f 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -396,7 +396,7 @@ static jv f_divide(jq_state *jq, jv input, jv a, jv b) { } } -#define dtoi(n) ((n) < INTMAX_MIN ? INTMAX_MIN : -(n) < INTMAX_MIN ? INTMAX_MAX : (intmax_t)(n)) +#define dtoi(n) ((n) < INTMAX_MIN ? INTMAX_MIN : -(n) <= INTMAX_MIN ? INTMAX_MAX : (intmax_t)(n)) static jv f_mod(jq_state *jq, jv input, jv a, jv b) { jv_free(input); if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) { diff --git a/src/parser.c b/src/parser.c index a1987d34a6..8dd9f87b4f 100644 --- a/src/parser.c +++ b/src/parser.c @@ -502,7 +502,7 @@ static block constant_fold(block a, block b, int op) { res = jv_number(na / nb); break; case '%': -#define is_unsafe_to_int_cast(n) (isnan(n) || (n) < INTMAX_MIN || -(n) < INTMAX_MIN) +#define is_unsafe_to_int_cast(n) (isnan(n) || (n) < INTMAX_MIN || -(n) <= INTMAX_MIN) if (is_unsafe_to_int_cast(na) || is_unsafe_to_int_cast(nb) || (intmax_t)nb == 0) return gen_noop(); #undef is_unsafe_to_int_cast res = jv_number((intmax_t)na % (intmax_t)nb); diff --git a/src/parser.y b/src/parser.y index 94ede7c4ab..bab2e48ca4 100644 --- a/src/parser.y +++ b/src/parser.y @@ -235,7 +235,7 @@ static block constant_fold(block a, block b, int op) { res = jv_number(na / nb); break; case '%': -#define is_unsafe_to_int_cast(n) (isnan(n) || (n) < INTMAX_MIN || -(n) < INTMAX_MIN) +#define is_unsafe_to_int_cast(n) (isnan(n) || (n) < INTMAX_MIN || -(n) <= INTMAX_MIN) if (is_unsafe_to_int_cast(na) || is_unsafe_to_int_cast(nb) || (intmax_t)nb == 0) return gen_noop(); #undef is_unsafe_to_int_cast res = jv_number((intmax_t)na % (intmax_t)nb);