From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp63.i.mail.ru (smtp63.i.mail.ru [217.69.128.43]) (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 8A0F642EF5C for ; Mon, 29 Jun 2020 16:29:58 +0300 (MSK) Date: Mon, 29 Jun 2020 13:29:57 +0000 From: Nikita Pettik Message-ID: <20200629132957.GB27240@tarantool.org> References: <010e6a896440f240f504daf8c72b71095a17869b.1593096639.git.imeevma@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <010e6a896440f240f504daf8c72b71095a17869b.1593096639.git.imeevma@gmail.com> Subject: Re: [Tarantool-patches] [PATCH v3 5/8] sql: remove mem_apply_type() from OP_MustBeInt List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org On 25 Jun 18:17, imeevma@tarantool.org wrote: > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > index 276956170..a609fa985 100644 > --- a/src/box/sql/vdbe.c > +++ b/src/box/sql/vdbe.c > @@ -2122,17 +2122,13 @@ 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 ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0 && > + mem_convert_to_integer(pIn1, true) != 0) { Please split this conditions into two branches. Like this: diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 2bc8c9817..da76d7321 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -2122,13 +2122,14 @@ case OP_AddImm: { /* in1 */ */ case OP_MustBeInt: { /* jump, in1 */ pIn1 = &aMem[pOp->p1]; - if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0 && - mem_convert_to_integer(pIn1, true) != 0) { - if (pOp->p2 != 0) - goto jump_to_p2; - diag_set(ClientError, ER_SQL_TYPE_MISMATCH, - sql_value_to_diag_str(pIn1), "integer"); - goto abort_due_to_error; + if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0) { + if (mem_convert_to_integer(pIn1, true) != 0) { + if (pOp->p2 != 0) + goto jump_to_p2; + diag_set(ClientError, ER_SQL_TYPE_MISMATCH, + sql_value_to_diag_str(pIn1), "integer"); + goto abort_due_to_error; + } } break; It ehcnances code readability. Or even integrate this check into mem_covert_to_ingeger(). The rest is OK (hope you carefully verified changed tests, since I've only briefly looked through).