From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 0BCBF2A237 for ; Thu, 29 Mar 2018 06:18:32 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xYwAUjOd2zxs for ; Thu, 29 Mar 2018 06:18:31 -0400 (EDT) Received: from smtp45.i.mail.ru (smtp45.i.mail.ru [94.100.177.105]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id BA98A2A20D for ; Thu, 29 Mar 2018 06:18:31 -0400 (EDT) From: AKhatskevich Subject: [tarantool-patches] [PATCH 3/3] sql: report errors in EphemeralGetMaxId Date: Thu, 29 Mar 2018 13:17:52 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: AKhatskevich In case of error in `tarantoolSqlite3EphemeralGetMaxId` it was creating diag string and silently continue working. It was a huge luck that non-valid output of the function did not lead to crashes. After the fix, it was found that some opcodes in `select.c` were using wrong registers. These were fixed too, but they still have bugs. For more information see #3297. Related to #3297 --- src/box/sql.c | 3 ++- src/box/sql/select.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/box/sql.c b/src/box/sql.c index 98bcd93ca..31ceacb53 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -1744,7 +1744,8 @@ int tarantoolSqlite3EphemeralGetMaxId(BtCursor *pCur, uint32_t fieldno, *max_id = 0; return SQLITE_OK; } - tuple_field_u64(tuple, fieldno, max_id); + if (tuple_field_u64(tuple, fieldno, max_id) == -1) + return SQL_TARANTOOL_ERROR; return SQLITE_OK; } diff --git a/src/box/sql/select.c b/src/box/sql/select.c index a76286f23..c91685f7f 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -1025,7 +1025,7 @@ selectInnerLoop(Parse * pParse, /* The parser context */ /* Last column is required for ID. */ int regCopy = sqlite3GetTempRange(pParse, nResultCol + 1); sqlite3VdbeAddOp3(v, OP_NextIdEphemeral, iParm, - 0, regCopy + nResultCol); + nResultCol, regCopy + nResultCol); /* Positioning ID column to be last in inserted tuple. * NextId -> regCopy + n + 1 * Copy [regResult, regResult + n] -> [regCopy, regCopy + n] @@ -1504,7 +1504,7 @@ generateSortTail(Parse * pParse, /* Parsing context */ case SRT_Table: case SRT_EphemTab: { int regCopy = sqlite3GetTempRange(pParse, nColumn); - sqlite3VdbeAddOp3(v, OP_NextIdEphemeral, iParm, 0, regTupleid); + sqlite3VdbeAddOp3(v, OP_NextIdEphemeral, iParm, nColumn, regTupleid); sqlite3VdbeAddOp3(v, OP_Copy, regRow, regCopy, nSortData - 1); sqlite3VdbeAddOp3(v, OP_MakeRecord, regCopy, nColumn + 1, regRow); sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, regRow); @@ -2957,7 +2957,7 @@ generateOutputSubroutine(Parse * pParse, /* Parsing context */ int regRec = sqlite3GetTempReg(pParse); int regCopy = sqlite3GetTempRange(pParse, pIn->nSdst + 1); sqlite3VdbeAddOp3(v, OP_NextIdEphemeral, pDest->iSDParm, - 0, regCopy + pIn->nSdst); + pIn->nSdst, regCopy + pIn->nSdst); sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regCopy, pIn->nSdst - 1); sqlite3VdbeAddOp3(v, OP_MakeRecord, regCopy, -- 2.14.1