Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Roman Khabibov <roman.habibov@tarantool.org>,
	tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 2/2] json: print context in error mesages
Date: Fri, 20 Dec 2019 00:19:37 +0100	[thread overview]
Message-ID: <7e6ac7e1-8d82-7a64-3d05-0de305917528@tarantool.org> (raw)
In-Reply-To: <d4a4c85c4c6b2041d7be1ce1c6f33351f6dcab7a.1576420905.git.roman.habibov@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)

  reply	other threads:[~2019-12-19 23:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-15 14:42 [Tarantool-patches] [PATCH v2 0/2] Improve json " Roman Khabibov
2019-12-15 14:42 ` [Tarantool-patches] [PATCH v2 1/2] json: make error messages more readable Roman Khabibov
2019-12-21 14:56   ` Roman Khabibov
2019-12-15 14:42 ` [Tarantool-patches] [PATCH v2 2/2] json: print context in error mesages Roman Khabibov
2019-12-19 23:19   ` Vladislav Shpilevoy [this message]
2019-12-21 14:56     ` Roman Khabibov

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=7e6ac7e1-8d82-7a64-3d05-0de305917528@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=roman.habibov@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 2/2] json: print context in error mesages' \
    /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