From 2123bf4b18a030c01d55ff5597fd80769cc7f5e5 Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Sat, 30 Jan 2021 15:15:02 -0500 Subject: [PATCH] Check all Subtract implementations for overflow. --- src/expr.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/expr.c b/src/expr.c index bbfc5aae..2d67d8d6 100644 --- a/src/expr.c +++ b/src/expr.c @@ -876,7 +876,9 @@ static int Subtract(void) /* If it's a date minus an int, do subtraction, checking for underflow */ if (v1.type == DATE_TYPE && v2.type == INT_TYPE) { + int old = v1.v.val; v1.v.val -= v2.v.val; + if (_private_sub_overflow(v1.v.val, v2.v.val, old)) return E_DATE_OVER; if (v1.v.val < 0) return E_DATE_OVER; PushValStack(v1); return OK; @@ -885,7 +887,9 @@ static int Subtract(void) /* If it's a datetime minus an int or a time, do subtraction, * checking for underflow */ if (v1.type == DATETIME_TYPE && (v2.type == INT_TYPE || v2.type == TIME_TYPE)) { + int old = v1.v.val; v1.v.val -= v2.v.val; + if (_private_sub_overflow(v1.v.val, v2.v.val, old)) return E_DATE_OVER; if (v1.v.val < 0) return E_DATE_OVER; PushValStack(v1); return OK; @@ -903,7 +907,9 @@ static int Subtract(void) if ((v1.type == TIME_TYPE && v2.type == TIME_TYPE) || (v1.type == DATETIME_TYPE && v2.type == DATETIME_TYPE) || (v1.type == DATE_TYPE && v2.type == DATE_TYPE)) { + int old = v1.v.val; v1.v.val -= v2.v.val; + if (_private_sub_overflow(v1.v.val, v2.v.val, old)) return E_DATE_OVER; v1.type = INT_TYPE; PushValStack(v1); return OK;