[Tarantool-patches] [PATCH v5 5/6] sql: fix implicit cast in opcode MustBeInt

imeevma at tarantool.org imeevma at tarantool.org
Fri Aug 21 12:19:56 MSK 2020


This patch removes implicit casting from STRING to number and vice
versa from MustBeInt opcode.

Part of #4230
---
 src/box/sql/vdbe.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index b326c4ba4..a0ddbaf60 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -2352,16 +2352,20 @@ case OP_AddImm: {            /* in1 */
  */
 case OP_MustBeInt: {            /* jump, in1 */
 	pIn1 = &aMem[pOp->p1];
-	if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0) {
-		mem_apply_type(pIn1, FIELD_TYPE_INTEGER);
-		if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0) {
-			if (pOp->p2==0) {
-				diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
-					 sql_value_to_diag_str(pIn1), "integer");
-				goto abort_due_to_error;
-			} else {
-				goto jump_to_p2;
-			}
+	if (mem_is_type_compatible(pIn1, FIELD_TYPE_INTEGER))
+		break;
+	if ((pIn1->flags & MEM_Real) != 0) {
+		double d = pIn1->u.r;
+		if (d == (double)(int64_t)d || d == (double)(uint64_t)d)
+			mem_convert_to_integer(pIn1);
+	}
+	if (!mem_is_type_compatible(pIn1, FIELD_TYPE_INTEGER)) {
+		if (pOp->p2==0) {
+			diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
+				 sql_value_to_diag_str(pIn1), "integer");
+			goto abort_due_to_error;
+		} else {
+			goto jump_to_p2;
 		}
 	}
 	break;
-- 
2.25.1



More information about the Tarantool-patches mailing list