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 861806BD0D; Sun, 11 Apr 2021 20:44:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 861806BD0D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618163095; bh=Kg6PfWlrwsii8tfhdtuIEMGdAsb5CDKNTt2YI3m6wq4=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=LJlG3Cr/P1+YnFKyvZxVv85QhiedGftVZk4F+OppyMLkBnN5B6B9XGPsGxHtleANK KcXeWBPrG9T9u/B+NNEPfOfgH+W3CBU3sbD+tOr+CI3F0bfTVFEtbeLxzFakFgdDPF TisvxYheUZ7neNxyHZ6jg2tSo24hQXwep6ACs1u0= 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 1B1966BD0C for ; Sun, 11 Apr 2021 20:44:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1B1966BD0C Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lVe8k-0001nN-AG; Sun, 11 Apr 2021 20:44:54 +0300 To: imeevma@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <2ce8b15b5c1869dec995b4a9f348fe7649f6af47.1617984948.git.imeevma@gmail.com> Message-ID: <6128a7ea-7fb9-8fd6-dc99-0feeb4759e6c@tarantool.org> Date: Sun, 11 Apr 2021 19:44:53 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: <2ce8b15b5c1869dec995b4a9f348fe7649f6af47.1617984948.git.imeevma@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480D608FE24BC85426BB1B55F651FED8C70182A05F53808504049A847B94665054BA41086A3D5D73FF2DC41C3F2CA520F42E03699DC5CAE0848 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7CB5C87C4C9A74E8BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063763305FB9D3ECC1898638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B26DD1B833B760CF3F36538264AA06A2BB98738A72DB41484ED2E47CDBA5A96583C09775C1D3CA48CFBCA4DA3BE1BC1572CC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92176DF2183F8FC7C0F75B7380DB97F9D88941B15DA834481F9449624AB7ADAF372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F83C798A30B85E16BA91E23F1B6B78B78B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A5F54B56BCFB8FBF7E2D82606DF7EA4EF95E82A365E0504138D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3407FE5477D6A8AF08214D1465BA68CBCF2B0BA74468E1B3F9CFDB0E087C3542EF753F339749AFF32E1D7E09C32AA3244CEE6C71BE7D5C383A4FD3EA6D0D6324BA30363D8B7DA7DD44FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyKKJYJ15DtJ7kstmutQhCg== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822D33C171836ADBBD2A2ECA5E73241037F3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v5 09/52] sql: introduce mem_str() 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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" I appreciate the work you did here! > diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c > index 79c3d60e0..b7e148422 100644 > --- a/src/box/sql/vdbeaux.c > +++ b/src/box/sql/vdbeaux.c > @@ -1108,21 +1108,10 @@ displayP4(Op * pOp, char *zTemp, int nTemp) > break; > } > case P4_MEM:{ > - Mem *pMem = pOp->p4.pMem; > - if (pMem->flags & MEM_Str) { > - zP4 = pMem->z; > - } else if (pMem->flags & MEM_Int) { > - sqlXPrintf(&x, "%lld", pMem->u.i); > - } else if (pMem->flags & MEM_UInt) { > - sqlXPrintf(&x, "%llu", pMem->u.u); > - } else if (pMem->flags & MEM_Real) { > - sqlXPrintf(&x, "%.16g", pMem->u.r); > - } else if (pMem->flags & MEM_Null) { > - zP4 = "NULL"; > - } else { > - assert(pMem->flags & MEM_Blob); > - zP4 = "(binary string)"; > - } > + const char *value = mem_str(pOp->p4.pMem); > + uint32_t size = MIN((int)strlen(value), nTemp - 1); > + memcpy(zP4, value, size); > + zP4[size] = '\0'; 'x' stays in an invalid state now, because its counter nChar is not updated. I would propose to use sqlStrAccumAppend/sqlStrAccumAppendAll instead of memcpy and manual 0 termination. The same below in sqlVdbeExpandSql(). > break; > } > case P4_INTARRAY:{ > diff --git a/src/box/sql/vdbetrace.c b/src/box/sql/vdbetrace.c > index e84bb3192..4ca56865d 100644 > --- a/src/box/sql/vdbetrace.c > +++ b/src/box/sql/vdbetrace.c > @@ -147,33 +145,11 @@ sqlVdbeExpandSql(Vdbe * p, /* The prepared statement being evaluated */ > zRawSql += nToken; > nextIndex = idx + 1; > assert(idx > 0 && idx <= p->nVar); > - pVar = &p->aVar[idx - 1]; > - if (pVar->flags & MEM_Null) { > - sqlStrAccumAppend(&out, "NULL", 4); > - } else if (pVar->flags & MEM_Int) { > - sqlXPrintf(&out, "%lld", pVar->u.i); > - } else if (pVar->flags & MEM_UInt) { > - sqlXPrintf(&out, "%llu", pVar->u.u); > - } else if (pVar->flags & MEM_Real) { > - sqlXPrintf(&out, "%!.15g", pVar->u.r); > - } else if (pVar->flags & MEM_Str) { > - int nOut; /* Number of bytes of the string text to include in output */ > - nOut = pVar->n; > - sqlXPrintf(&out, "'%.*q'", nOut, pVar->z); > - } else if (pVar->flags & MEM_Zero) { > - sqlXPrintf(&out, "zeroblob(%d)", > - pVar->u.nZero); > - } else { > - int nOut; /* Number of bytes of the blob to include in output */ > - assert(pVar->flags & MEM_Blob); > - sqlStrAccumAppend(&out, "x'", 2); > - nOut = pVar->n; > - for (i = 0; i < nOut; i++) { > - sqlXPrintf(&out, "%02x", > - pVar->z[i] & 0xff); > - } > - sqlStrAccumAppend(&out, "'", 1); > - } > + const char *value = mem_str(&p->aVar[idx - 1]); > + uint32_t len = strlen(value); > + uint32_t size = MIN(len, sizeof(zBase) - 1); > + memcpy(zBase, value, size); > + zBase[size] = '\0'; > } > } > if (out.accError) >