From 692d8e9685ce0c4e9293b31fca69115add7a479b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 5 Dec 2018 12:32:20 +1030 Subject: [PATCH] json: simplify json_tok_copy. Also fixes NULL case (we called tok_next() before NULL check). Signed-off-by: Rusty Russell --- common/json.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/common/json.c b/common/json.c index 3af957d51..c4c511478 100644 --- a/common/json.c +++ b/common/json.c @@ -251,17 +251,7 @@ void json_tok_print(const char *buffer, const jsmntok_t *tok) jsmntok_t *json_tok_copy(const tal_t *ctx, const jsmntok_t *tok) { - const jsmntok_t *first = tok; - const jsmntok_t *last = json_next(tok); - - if (!tok) - return NULL; - jsmntok_t *arr = tal_arr(ctx, jsmntok_t, last - first); - jsmntok_t *dest = arr; - while (first != last) - *dest++ = *first++; - - return arr; + return tal_dup_arr(ctx, jsmntok_t, tok, json_next(tok) - tok, 0); } void json_tok_remove(jsmntok_t **tokens, jsmntok_t *tok, size_t num)