From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 5AA946D3F5; Mon, 25 Oct 2021 11:46:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5AA946D3F5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1635151561; bh=9kvnecGio7MWh31LZCruzaqM1XnNqhlEtvCoL3Quib8=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=hGUugFAoNzzhZQapgYAPM+hH+KT/HyZMFNMwD5vsBW3DwboQD2rDHthwdrMLwtJ19 SsY3QIIiywGZI8JDT5JgPwuE0xoB7ib1izZInCCpQaAPSXZpP5Z2vxl1I30fUbz1ss 7/OM+q+zC3t1xgzCGe/calPdhIthGosQy+bICYXk= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 CD5BD6D3F5 for ; Mon, 25 Oct 2021 11:46:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CD5BD6D3F5 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mevcG-0006No-4z; Mon, 25 Oct 2021 11:46:00 +0300 Date: Mon, 25 Oct 2021 11:45:58 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20211025084558.GK36295@tarantool.org> References: <1a76cd1ebe317799fc224382efffb9365b075968.1633713432.git.imeevma@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9C7814344C8C501C8A4649CC2A06649B6A97F49A0BDC630D4182A05F5380850404A4490EEAA56258B5B16181601FB837ECA6E65C8CD9ADF352DE5FAE4848CC9C4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F2EC3597058CFA6DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006376EC5B14D896A2D978638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8E68A00BA8EC50A6A9F73D0F1041ED111117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5F4A40DA7C94F3EAFFC18505F5ABE0E21F9D004FE949C0D9AD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75FA7FF33AA1A4D21C410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D9DC20663B80603FF2656F86AC8C8DFCB3C224CD5C5F1EDA620CCA6C6E1C9EC99B9FC75EF3B3F8711D7E09C32AA3244C0F99EA3234626ACCBFBC8B4C6B2E4E808580396430872480729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojPL6H901iH3EPcQB5DEkiPQ== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D2D5F3C986608A3A36982AEB6A030095683D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 16/21] sql: refactor REPLACE() function X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: Mergen Imeev Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thank you for the review! My answer and diff below. On Fri, Oct 15, 2021 at 12:45:29AM +0200, Vladislav Shpilevoy wrote: > Thanks for the patch! > > On 08.10.2021 19:32, Mergen Imeev via Tarantool-patches wrote: > > Part of #4145 > > --- > > src/box/sql/func.c | 58 ++++++++++++++++------------------------------ > > 1 file changed, 20 insertions(+), 38 deletions(-) > > > > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > > index a3ca53545..f26d101e9 100644 > > --- a/src/box/sql/func.c > > +++ b/src/box/sql/func.c > > @@ -1460,34 +1460,26 @@ replaceFunc(struct sql_context *context, int argc, struct Mem *argv) > > int i, j; /* Loop counters */ > > > > assert(argc == 3); > > - UNUSED_PARAMETER(argc); > > - zStr = mem_as_ustr(&argv[0]); > > - if (zStr == 0) > > - return; > > - nStr = mem_len_unsafe(&argv[0]); > > - assert(zStr == mem_as_ustr(&argv[0])); /* No encoding change */ > > - zPattern = mem_as_ustr(&argv[1]); > > - if (zPattern == 0) { > > - assert(mem_is_null(&argv[1]) > > - || sql_context_db_handle(context)->mallocFailed); > > + (void)argc; > > + if (mem_is_any_null(&argv[0], &argv[1]) || mem_is_null(&argv[2])) > > return; > > - } > > - nPattern = mem_len_unsafe(&argv[1]); > > + assert(mem_is_bytes); > > 1. You forgot to call the function. > Thanks, fixed. > > + zStr = (const unsigned char *)argv[0].z; > > + nStr = argv[0].n; > > + zPattern = (const unsigned char *)argv[1].z; > > + nPattern = argv[1].n; > > if (nPattern == 0) { > > - assert(!mem_is_null(&argv[1])); > > - sql_result_value(context, &argv[0]); > > + if (mem_copy(context->pOut, &argv[0]) != 0) > > + context->is_aborted = true; > > return; > > @@ -1497,22 +1489,12 @@ replaceFunc(struct sql_context *context, int argc, struct Mem *argv) > > zOut[j++] = zStr[i]; > > } else { > > u8 *zOld; > > - sql *db = sql_context_db_handle(context); > > nOut += nRep - nPattern; > > - testcase(nOut - 1 == db->aLimit[SQL_LIMIT_LENGTH]); > > - testcase(nOut - 2 == db->aLimit[SQL_LIMIT_LENGTH]); > > - if (nOut - 1 > db->aLimit[SQL_LIMIT_LENGTH]) { > > 2. Why did you drop length limit assertions and checks? > These assertions do nothing, since testcase macro defined this way: #define testcase(X) I don't think we should check the length of the STRING and VARBINARY values in functions, since the result is checked in the VDBE. > > - diag_set(ClientError, ER_SQL_EXECUTE, "string "\ > > - "or binary string is too big"); > > - context->is_aborted = true; > > - sql_free(zOut); > > - return; > > - } Diff: diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 91ff741df..f7024a9b9 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1485,7 +1485,8 @@ replaceFunc(struct sql_context *context, int argc, struct Mem *argv) (void)argc; if (mem_is_any_null(&argv[0], &argv[1]) || mem_is_null(&argv[2])) return; - assert(mem_is_bytes); + assert(mem_is_bytes(&argv[0]) && mem_is_bytes(&argv[1]) && + mem_is_bytes(&argv[2])); zStr = (const unsigned char *)argv[0].z; nStr = argv[0].n; zPattern = (const unsigned char *)argv[1].z;