mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2025-12-30 10:20:06 +01:00
spa-json: only add the json data represented by its size
The data pointer of a WpSpaJson object can be bigger than the actual WpSpaJson size. For example, this happens when iterating an array: instead of re-allocating the nested data into a new region of memory, the iterator uses the same region of memory as the parent, and just sets the pointer data and size to the correct location when creating the nested WpSpaJson object. This patch makes sure only the data represented by the size is added into the builder when adding a json object, fixing issues that were happening before when adding nested objects directly from a second WpSpaJson object.
This commit is contained in:
parent
8ade19ac59
commit
a19c7f3d2f
1 changed files with 10 additions and 2 deletions
|
|
@ -953,6 +953,14 @@ builder_add_formatted (WpSpaJsonBuilder *self, const gchar *fmt, ...)
|
|||
self->size += s;
|
||||
}
|
||||
|
||||
static void
|
||||
builder_add_json (WpSpaJsonBuilder *self, WpSpaJson *json)
|
||||
{
|
||||
g_return_if_fail (self->max_size - self->size >= json->size + 1);
|
||||
snprintf (self->data + self->size, json->size + 1, "%s", json->data);
|
||||
self->size += json->size;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds a property into the builder
|
||||
*
|
||||
|
|
@ -1053,14 +1061,14 @@ wp_spa_json_builder_add_string (WpSpaJsonBuilder *self, const gchar *value)
|
|||
*
|
||||
* \ingroup wpspajson
|
||||
* \param self the spa json builder object
|
||||
* \param json the json value
|
||||
* \param json (transfer none): the json value
|
||||
*/
|
||||
void
|
||||
wp_spa_json_builder_add_json (WpSpaJsonBuilder *self, WpSpaJson *json)
|
||||
{
|
||||
ensure_separator (self, FALSE);
|
||||
ensure_allocated_max_size (self, json->size);
|
||||
builder_add_formatted (self, "%s", json->data);
|
||||
builder_add_json (self, json);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue