From: Kirill Shcherbatov <kshcherbatov@tarantool.org> To: tarantool-patches@freelists.org, v.shpilevoy@tarantool.org Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org> Subject: [tarantool-patches] [PATCH v2 1/7] sql: refactor sql_alloc_src_list to set diag Date: Wed, 27 Feb 2019 14:13:12 +0300 [thread overview] Message-ID: <9bc544e742ad88f4fd6a3738fb4993d789832bc6.1551265819.git.kshcherbatov@tarantool.org> (raw) In-Reply-To: <cover.1551265819.git.kshcherbatov@tarantool.org> Refactored sql_alloc_src_list routine to use diag_set in case of memory allocation error. This will ensure that the sqlSrcListAppend function throws an error using diag in subsequent patches. Needed for #3931 --- src/box/sql/build.c | 30 +++++++++++++++++------------- src/box/sql/sqlInt.h | 12 ++++++++++-- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index e9851d9a1..3a65eb5a1 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -1397,8 +1397,11 @@ vdbe_emit_stat_space_clear(struct Parse *parse, const char *stat_table_name, struct sql *db = parse->db; assert(!db->mallocFailed); struct SrcList *src_list = sql_alloc_src_list(db); - if (src_list != NULL) - src_list->a[0].zName = sqlDbStrDup(db, stat_table_name); + if (src_list == NULL) { + sql_parser_error(parse); + return; + } + src_list->a[0].zName = sqlDbStrDup(db, stat_table_name); struct Expr *where = NULL; if (idx_name != NULL) { struct Expr *expr = sql_id_eq_str_expr(parse, "idx", idx_name); @@ -2666,19 +2669,20 @@ sqlSrcListEnlarge(sql * db, /* Database connection to notify of OOM errors */ return pSrc; } -SrcList * -sql_alloc_src_list(sql *db) +struct SrcList * +sql_alloc_src_list(struct sql *db) { - SrcList *pList; - - pList = sqlDbMallocRawNN(db, sizeof(SrcList)); - if (pList == 0) + struct SrcList *src_list = sqlDbMallocRawNN(db, sizeof(SrcList)); + if (src_list == NULL) { + diag_set(OutOfMemory, sizeof(SrcList), "sqlDbMallocRawNN", + "src_list"); return NULL; - pList->nAlloc = 1; - pList->nSrc = 1; - memset(&pList->a[0], 0, sizeof(pList->a[0])); - pList->a[0].iCursor = -1; - return pList; + } + src_list->nAlloc = 1; + src_list->nSrc = 1; + memset(&src_list->a[0], 0, sizeof(src_list->a[0])); + src_list->a[0].iCursor = -1; + return src_list; } /* diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index dbfdbc6f5..ce29dc0b1 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -3427,8 +3427,16 @@ void *sqlArrayAllocate(sql *, void *, int, int *, int *); IdList *sqlIdListAppend(sql *, IdList *, Token *); int sqlIdListIndex(IdList *, const char *); SrcList *sqlSrcListEnlarge(sql *, SrcList *, int, int); -SrcList * -sql_alloc_src_list(sql *db); + +/** + * Allocate a new empty SrcList object. + * @param db The database connection. + * @retval not NULL list pointer on success. + * @retval NULL otherwise. + */ +struct SrcList * +sql_alloc_src_list(struct sql *db); + SrcList *sqlSrcListAppend(sql *, SrcList *, Token *); SrcList *sqlSrcListAppendFromTerm(Parse *, SrcList *, Token *, Token *, Select *, Expr *, IdList *); -- 2.20.1
next prev parent reply other threads:[~2019-02-27 11:13 UTC|newest] Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-02-27 11:13 [tarantool-patches] [PATCH v2 0/7] sql: store regular identifiers in case-normal form Kirill Shcherbatov 2019-02-27 11:13 ` Kirill Shcherbatov [this message] 2019-03-07 17:34 ` [tarantool-patches] Re: [PATCH v2 1/7] sql: refactor sql_alloc_src_list to set diag Vladislav Shpilevoy 2019-03-11 15:04 ` Kirill Shcherbatov 2019-02-27 11:13 ` [tarantool-patches] [PATCH v2 2/7] sql: rework sql_src_list_enlarge " Kirill Shcherbatov 2019-03-07 17:34 ` [tarantool-patches] " Vladislav Shpilevoy 2019-03-11 15:04 ` Kirill Shcherbatov 2019-02-27 11:13 ` [tarantool-patches] [PATCH v2 3/7] sql: refactor sql_src_list_append " Kirill Shcherbatov 2019-03-07 17:34 ` [tarantool-patches] " Vladislav Shpilevoy 2019-03-11 15:04 ` Kirill Shcherbatov 2019-03-18 19:33 ` Vladislav Shpilevoy 2019-03-20 11:02 ` Kirill Shcherbatov 2019-03-26 17:08 ` Vladislav Shpilevoy 2019-03-26 18:07 ` Vladislav Shpilevoy 2019-02-27 11:13 ` [tarantool-patches] [PATCH v2 4/7] sql: refactor sql_name_from_token " Kirill Shcherbatov 2019-03-07 17:34 ` [tarantool-patches] " Vladislav Shpilevoy 2019-03-11 15:04 ` Kirill Shcherbatov 2019-03-18 19:33 ` Vladislav Shpilevoy 2019-03-20 11:02 ` Kirill Shcherbatov 2019-02-27 11:13 ` [tarantool-patches] [PATCH v2 5/7] sql: refactor sql_trigger_step_allocate " Kirill Shcherbatov 2019-03-07 17:34 ` [tarantool-patches] " Vladislav Shpilevoy 2019-03-11 15:04 ` Kirill Shcherbatov 2019-03-18 19:33 ` Vladislav Shpilevoy 2019-03-20 11:02 ` Kirill Shcherbatov 2019-03-26 17:08 ` Vladislav Shpilevoy 2019-02-27 11:13 ` [tarantool-patches] [PATCH v2 6/7] sql: refactor sql_expr_create " Kirill Shcherbatov 2019-03-07 17:34 ` [tarantool-patches] " Vladislav Shpilevoy 2019-03-11 15:04 ` Kirill Shcherbatov 2019-03-18 19:33 ` Vladislav Shpilevoy 2019-03-20 11:02 ` Kirill Shcherbatov 2019-03-26 17:08 ` Vladislav Shpilevoy 2019-02-27 11:13 ` [tarantool-patches] [PATCH v2 7/7] sql: store regular identifiers in case-normal form Kirill Shcherbatov 2019-03-07 17:34 ` [tarantool-patches] " Vladislav Shpilevoy 2019-03-11 15:04 ` Kirill Shcherbatov 2019-03-18 19:33 ` Vladislav Shpilevoy 2019-03-20 11:02 ` Kirill Shcherbatov 2019-03-26 17:08 ` Vladislav Shpilevoy 2019-03-18 19:33 ` [tarantool-patches] Re: [PATCH v2 0/7] " Vladislav Shpilevoy 2019-03-20 11:02 ` Kirill Shcherbatov 2019-03-26 17:09 ` Vladislav Shpilevoy 2019-03-27 14:06 ` Kirill Yukhin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=9bc544e742ad88f4fd6a3738fb4993d789832bc6.1551265819.git.kshcherbatov@tarantool.org \ --to=kshcherbatov@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [tarantool-patches] [PATCH v2 1/7] sql: refactor sql_alloc_src_list to set diag' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox