Browse Source

json: simplify json_tok_copy.

Also fixes NULL case (we called tok_next() before NULL check).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
plugin-6
Rusty Russell 6 years ago
committed by Christian Decker
parent
commit
692d8e9685
  1. 12
      common/json.c

12
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)

Loading…
Cancel
Save