Skip to content

Commit

Permalink
fix: passing complete buf size argument to _jsonb_escape
Browse files Browse the repository at this point in the history
  • Loading branch information
anibalportero committed Aug 31, 2022
1 parent 9079145 commit c8c5998
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions json-build.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ jsonb_init(jsonb *b)
}

JSONB_API jsonbcode
jsonb_object(jsonb *b, char buf[], size_t bufsize)
{
jsonb_object(jsonb *b, char buf[], size_t bufsize) {
enum jsonbstate new_state;
size_t pos = 0;
if (b->top - b->stack >= JSONB_MAX_DEPTH) return JSONB_ERROR_STACK;
Expand Down Expand Up @@ -400,7 +399,7 @@ jsonb_key(jsonb *b, char buf[], size_t bufsize, const char key[], size_t len)
case JSONB_OBJECT_KEY_OR_CLOSE: {
enum jsonbcode ret;
BUFFER_COPY_CHAR(b, '"', pos, buf, bufsize);
ret = _jsonb_escape(&pos, buf + b->pos, bufsize, key, len);
ret = _jsonb_escape(&pos, buf + b->pos, bufsize - b->pos, key, len);
if (ret != JSONB_OK) return ret;
BUFFER_COPY(b, "\":", 2, pos, buf, bufsize);
STACK_HEAD(b, JSONB_OBJECT_VALUE);
Expand Down Expand Up @@ -551,7 +550,7 @@ jsonb_string(
return JSONB_ERROR_INPUT;
}
BUFFER_COPY_CHAR(b, '"', pos, buf, bufsize);
ret = _jsonb_escape(&pos, buf + b->pos, bufsize, str, len);
ret = _jsonb_escape(&pos, buf + b->pos, bufsize - b->pos, str, len);
if (ret != JSONB_OK) return ret;
BUFFER_COPY_CHAR(b, '"', pos, buf, bufsize);
STACK_HEAD(b, next_state);
Expand Down

0 comments on commit c8c5998

Please sign in to comment.