Skip to content

Commit

Permalink
allocate the stringinfodata on the stack
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Feb 25, 2022
1 parent 62f4733 commit 14f1e4f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ Datum urlencode_jsonb(PG_FUNCTION_ARGS)
JsonbIterator *it;
JsonbValue v;
JsonbIteratorToken r;
StringInfo si;
StringInfoData si;
size_t count = 0;

if (!JB_ROOT_IS_OBJECT(jb))
Expand All @@ -1493,7 +1493,7 @@ Datum urlencode_jsonb(PG_FUNCTION_ARGS)
}

/* Buffer to write complete output into */
si = makeStringInfo();
initStringInfo(&si);

it = JsonbIteratorInit(&jb->root);
while ((r = JsonbIteratorNext(&it, &v, skipNested)) != WJB_DONE)
Expand Down Expand Up @@ -1550,8 +1550,8 @@ Datum urlencode_jsonb(PG_FUNCTION_ARGS)
}
/* Write the result */
value_enc = urlencode_cstr(value, strlen(value));
if (count++) appendStringInfo(si, "&");
appendStringInfo(si, "%s=%s", key_enc, value_enc);
if (count++) appendStringInfo(&si, "&");
appendStringInfo(&si, "%s=%s", key_enc, value_enc);

/* Clean up temporary strings */
if (key) pfree(key);
Expand All @@ -1561,8 +1561,8 @@ Datum urlencode_jsonb(PG_FUNCTION_ARGS)
}
}

if (si->len)
PG_RETURN_TEXT_P(cstring_to_text_with_len(si->data, si->len));
if (si.len)
PG_RETURN_TEXT_P(cstring_to_text_with_len(si.data, si.len));
else
PG_RETURN_NULL();
}
Expand Down

0 comments on commit 14f1e4f

Please sign in to comment.