mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-04-14 05:30:39 +02:00
spa-json: allocate enough space for parsing strings without looping
The string size is always less or equal to the size of the token (len), so by allocating len+1 bytes we have enough space to write the whole token and the null byte, if needed.
This commit is contained in:
parent
2248b8ec1f
commit
8d4fe81ebd
1 changed files with 3 additions and 10 deletions
|
|
@ -624,16 +624,9 @@ wp_spa_json_parse_float (WpSpaJson *self, float *value)
|
|||
static gchar *
|
||||
wp_spa_json_parse_string_internal (const gchar *data, int len)
|
||||
{
|
||||
size_t size = WP_SPA_JSON_STRING_INIT_SIZE;
|
||||
gchar *res = NULL;
|
||||
|
||||
res = g_new0(gchar, size);
|
||||
while (spa_json_parse_stringn(data, len, res, size) < 0)
|
||||
{
|
||||
size *= 2;
|
||||
res = g_realloc(res, size);
|
||||
}
|
||||
|
||||
gchar *res = g_new0 (gchar, len+1);
|
||||
if (res)
|
||||
spa_json_parse_string (data, len, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue