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 5CD1D6EC5F; Thu, 15 Apr 2021 01:23:42 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5CD1D6EC5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618439022; bh=Uf3WiNXCHsqB2E0rtpyYJX7/GyrQr12boKLWSxPWyOc=; 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=NaQoZ40GtJdc5+D7JZnv/3J8yw0PaewZgg3umTY2VgM5OAncrQLV/YbZHZtZzmQaT MOm9aesj4Zj0gSt5BZy4MwKuDhsIv3T/nH6acP6Re1iXfMhbPtB60TYj4sxAp2AIP4 dCX8FxyEDBdQOGF28hHo25qmPvHUZRC4lJFME7wA= 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 683296EC5F for ; Thu, 15 Apr 2021 01:23:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 683296EC5F Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lWnv7-00088p-RF; Thu, 15 Apr 2021 01:23:38 +0300 To: Mergen Imeev Cc: tarantool-patches@dev.tarantool.org References: <2ce8b15b5c1869dec995b4a9f348fe7649f6af47.1617984948.git.imeevma@gmail.com> <6128a7ea-7fb9-8fd6-dc99-0feeb4759e6c@tarantool.org> <20210413123601.GA108689@tarantool.org> Message-ID: Date: Thu, 15 Apr 2021 00:23:36 +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: <20210413123601.GA108689@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480EBD5CA77A668ECB87DA2124B0A8E6609182A05F538085040FFA641D81A10DAC03B05A348C554251171D6CF8E9881CC784DF6C67D1B5669F5 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DFF8C1C3012D6F1AEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637A164EE347039141E8638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2E7CBDDED9D9C964D707361F16C1F751A21114FFCE5AE9CDCD2E47CDBA5A96583C09775C1D3CA48CFED8438A78DFE0A9E117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE77A825AB47F0FC8649FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA73A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E7358CCB3ED2A1DE2304C4224003CC83647689D4C264860C145E X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C97831484992430F8B99B50ECBE94767D537CD X-C1DE0DAB: 0D63561A33F958A5F4A106C759A25BCF5C3CC899342EEA7120A9A1CD7D87F594D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C1E32F4AD4B2486B5FC0388FFF690B56F567BDBDBC6B234F507DB579BB1EB6A69EAA6C66C40DDCAA1D7E09C32AA3244C9D7BFA2A6C7037B9E226D7B27239B8F235DA7DC5AF9B58C0729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojrcJA+pXcDun7fJcEHOtQGg== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822849E1650C5FCB5FBB580C8C721FDFDBD3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B 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" Good job on the fixes! > diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c > index 79c3d60e0..907c9f5c6 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); > + int len = strlen(value); > + uint32_t size = MIN(len, nTemp - 1); Why do you need that limit? The accum is created as sqlStrAccumInit(&x, 0, zTemp, nTemp, 0). The last argument 0 means it won't realloc anything, so it is safe to append. The same in the next diff hunk. Consider this diff: ==================== diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index a2a0fc33e..95a035fd4 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -52,7 +52,9 @@ mem_str(const struct Mem *mem) case MEM_Null: return "NULL"; case MEM_Str: - return tt_sprintf("%.*s", mem->n, mem->z); + if ((mem->flags & MEM_Term) != 0) + return mem->z; + return tt_cstr(mem->z, mem->n); case MEM_Int: return tt_sprintf("%lld", mem->u.i); case MEM_UInt: @@ -68,9 +70,8 @@ mem_str(const struct Mem *mem) case MEM_Bool: return mem->u.b ? "TRUE" : "FALSE"; default: - break; + return "unknown"; } - return "unknown"; } static inline bool diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c index 907c9f5c6..9ef0445bd 100644 --- a/src/box/sql/vdbeaux.c +++ b/src/box/sql/vdbeaux.c @@ -1109,9 +1109,7 @@ displayP4(Op * pOp, char *zTemp, int nTemp) } case P4_MEM:{ const char *value = mem_str(pOp->p4.pMem); - int len = strlen(value); - uint32_t size = MIN(len, nTemp - 1); - sqlStrAccumAppend(&x, value, size); + sqlStrAccumAppend(&x, value, strlen(value)); break; } case P4_INTARRAY:{ diff --git a/src/box/sql/vdbetrace.c b/src/box/sql/vdbetrace.c index 677de65e2..a26880041 100644 --- a/src/box/sql/vdbetrace.c +++ b/src/box/sql/vdbetrace.c @@ -146,9 +146,7 @@ sqlVdbeExpandSql(Vdbe * p, /* The prepared statement being evaluated */ nextIndex = idx + 1; assert(idx > 0 && idx <= p->nVar); const char *value = mem_str(&p->aVar[idx - 1]); - uint32_t len = strlen(value); - uint32_t size = MIN(len, sizeof(zBase) - 1); - sqlStrAccumAppend(&out, value, size); + sqlStrAccumAppend(&out, value, strlen(value)); } } if (out.accError)