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 126C22BF5A for ; Fri, 5 Apr 2019 10:57:55 -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 Wd_pLSguFGt8 for ; Fri, 5 Apr 2019 10:57:54 -0400 (EDT) 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 turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 358D12B6A3 for ; Fri, 5 Apr 2019 10:57:54 -0400 (EDT) From: Ivan Koptelov Subject: [tarantool-patches] [PATCH 1/2] sql: make aggregate functions types more strict Date: Fri, 5 Apr 2019 17:57:43 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, korablev@tarantool.org Cc: Ivan Koptelov Let's firstly fix code-style. --- src/box/sql/func.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index b86a95d9a..b1bfc886e 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1585,23 +1585,22 @@ countFinalize(sql_context * context) * Routines to implement min() and max() aggregate functions. */ static void -minmaxStep(sql_context * context, int NotUsed, sql_value ** argv) +minmaxStep(sql_context *context, int not_used, sql_value **argv) { - Mem *pArg = (Mem *) argv[0]; - Mem *pBest; - UNUSED_PARAMETER(NotUsed); + UNUSED_PARAMETER(not_used); + sql_value *arg = argv[0]; + sql_value *best = sql_aggregate_context(context, sizeof(*best)); - pBest = (Mem *) sql_aggregate_context(context, sizeof(*pBest)); - if (!pBest) + if (best == NULL) return; if (sql_value_type(argv[0]) == SQL_NULL) { - if (pBest->flags) + if (best->flags != 0) sqlSkipAccumulatorLoad(context); - } else if (pBest->flags) { + } else if (best->flags != 0) { int max; int cmp; - struct coll *pColl = sqlGetFuncCollSeq(context); + struct coll *coll = sqlGetFuncCollSeq(context); /* This step function is used for both the min() and max() aggregates, * the only difference between the two being that the sense of the * comparison is inverted. For the max() aggregate, the @@ -1611,15 +1610,15 @@ minmaxStep(sql_context * context, int NotUsed, sql_value ** argv) * aggregate, or 0 for min(). */ max = sql_user_data(context) != 0; - cmp = sqlMemCompare(pBest, pArg, pColl); - if ((max && cmp < 0) || (!max && cmp > 0)) { - sqlVdbeMemCopy(pBest, pArg); + cmp = sqlMemCompare(best, arg, coll); + if ((max != 0 && cmp < 0) || (max == 0 && cmp > 0)) { + sqlVdbeMemCopy(best, arg); } else { sqlSkipAccumulatorLoad(context); } } else { - pBest->db = sql_context_db_handle(context); - sqlVdbeMemCopy(pBest, pArg); + best->db = sql_context_db_handle(context); + sqlVdbeMemCopy(best, arg); } } @@ -1628,8 +1627,8 @@ minMaxFinalize(sql_context * context) { sql_value *pRes; pRes = (sql_value *) sql_aggregate_context(context, 0); - if (pRes) { - if (pRes->flags) { + if (pRes != NULL) { + if (pRes->flags != 0) { sql_result_value(context, pRes); } sqlVdbeMemRelease(pRes); -- 2.20.1