From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp44.i.mail.ru (smtp44.i.mail.ru [94.100.177.104]) (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 5AD5D46970E for ; Fri, 20 Dec 2019 02:19:39 +0300 (MSK) References: From: Vladislav Shpilevoy Message-ID: <7e6ac7e1-8d82-7a64-3d05-0de305917528@tarantool.org> Date: Fri, 20 Dec 2019 00:19:37 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Tarantool-patches] [PATCH v2 2/2] json: print context in error mesages List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Roman Khabibov , tarantool-patches@dev.tarantool.org Hi! Thanks for the patch! See my review fixes here and on top of the branch. Please, review them, and if you are ok, then squash. In that case it will be LGTM. ============================================================================== diff --git a/third_party/lua-cjson/lua_cjson.c b/third_party/lua-cjson/lua_cjson.c index 655d6550e..79b0253f0 100644 --- a/third_party/lua-cjson/lua_cjson.c +++ b/third_party/lua-cjson/lua_cjson.c @@ -847,26 +847,24 @@ static void fill_context(char *context, json_parse_t *json, int column_index) { assert(column_index >= 0); int length_before = column_index < CONTEXT_MAX_LENGTH_BEFORE ? - column_index : CONTEXT_MAX_LENGTH_BEFORE; + column_index : CONTEXT_MAX_LENGTH_BEFORE; const char *src = json->cur_line_ptr + column_index - length_before; - int i = 0; /* Fill context before the arrow. */ - for (; i < length_before; i++) - context[i] = src[i]; + memcpy(context, src, length_before); + context += length_before; + src += length_before; /* Make the arrow. */ - context[i] = ' '; - memset(context + i + 1, '>', CONTEXT_ARROW_LENGTH - 2); - context[i + CONTEXT_ARROW_LENGTH - 1] = ' '; + *(context++) = ' '; + memset(context, '>', CONTEXT_ARROW_LENGTH - 2); + context += CONTEXT_ARROW_LENGTH - 2; + *(context++) = ' '; /* Fill context after the arrow. */ - for (int n = 0; n < CONTEXT_MAX_LENGTH_AFTER && src[i] != '\0' && - src[i] != '\n'; i++) { - context[i + CONTEXT_ARROW_LENGTH] = src[i]; - n++; - } - assert(i + CONTEXT_ARROW_LENGTH <= CONTEXT_MAX_LENGTH); - context[i + CONTEXT_ARROW_LENGTH] = '\0'; + const char *end = context + CONTEXT_MAX_LENGTH_AFTER; + for (; context < end && *src != '\0' && *src != '\n'; ++src, ++context) + *context = *src; + *context = '\0'; } /* This function does not return. @@ -893,8 +891,7 @@ static void json_throw_parse_error(lua_State *l, json_parse_t *json, /* Note: token->column_index is 0 based, display starting from 1 */ luaL_error(l, "Expected %s but found %s on line %d at character %d here " - "'%s'", exp, found, json->line_count, token->column_index + 1, - context); + "'%s'", exp, found, json->line_count, column_index + 1, context); } static inline void json_decode_ascend(json_parse_t *json)