[PATCH] MDEV-26645: Fix UB in Item_func_plus and Item_func_minus
authorMarko Mäkelä <marko.makela@mariadb.com>
Fri, 18 Feb 2022 14:31:54 +0000 (16:31 +0200)
committerPeter Michael Green <plugwash@raspbian.org>
Thu, 17 Mar 2022 23:44:37 +0000 (23:44 +0000)
commitdebc9ac9bb8811e2d788e415ce7669afb76ffa86
tree3541a3da8f55a9be780fd405c9a95d5a366e56fa
parent8b9961553059f750f4c26467ce00755b414baa30
[PATCH] MDEV-26645: Fix UB in Item_func_plus and Item_func_minus

An integer overflow in an expression like a+b or a-b is undefined behavior.
The compiler is allowed to assume that no such overflow is possible,
and optimize away some code accordingly.

Item_func_plus::int_op(), Item_func_minus::int_op(): Always check
for overflow.

Depending on the compiler and the compilation options, a test might fail:

CURRENT_TEST: main.func_math
mysqltest: At line 425: query 'SELECT 9223372036854775807 + 9223372036854775807' succeeded - should have failed with errno 1690...

A similar bug had been fixed earlier in
commit 328edf8560dbf1941ce314fa112e0db05d9f97f1.

This commit was backported from MariaDB 10.9 to Debian with MariaDB 10.6.

Gbp-Pq: Name MDEV-26645-fix-test-main.func_math.patch
sql/item_func.cc