Skip to content

Commit

Permalink
pack: json: do not create an empty msgpack buffer if no tokens exists (
Browse files Browse the repository at this point in the history
…#527)

Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Mar 5, 2018
1 parent 791c260 commit ae3e964
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/flb_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ static char *tokens_to_msgpack(char *js,
msgpack_packer pck;
msgpack_sbuffer sbuf;

if (arr_size == 0) {
return NULL;
}

/* initialize buffers */
msgpack_sbuffer_init(&sbuf);
msgpack_packer_init(&pck, &sbuf, msgpack_sbuffer_write);
Expand All @@ -112,7 +116,6 @@ static char *tokens_to_msgpack(char *js,
}

flen = (t->end - t->start);

switch (t->type) {
case JSMN_OBJECT:
msgpack_pack_map(&pck, t->size);
Expand Down Expand Up @@ -177,7 +180,7 @@ int flb_pack_json(char *js, size_t len, char **buffer, int *size)
{
int ret = -1;
int out;
char *buf;
char *buf = NULL;
struct flb_pack_state state;

ret = flb_pack_state_init(&state);
Expand Down

0 comments on commit ae3e964

Please sign in to comment.