From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 6F4D1430411 for ; Fri, 21 Aug 2020 12:19:57 +0300 (MSK) From: imeevma@tarantool.org Date: Fri, 21 Aug 2020 12:19:56 +0300 Message-Id: <660af07f4a4cf50567ee5ca845cfa538f316e9f4.1598000242.git.imeevma@gmail.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v5 5/6] sql: fix implicit cast in opcode MustBeInt List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: korablev@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org 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