aggregator: Make parsing of explicit sink pad names more robust

When passing "sink_%d" twice to aggregator before it would create two
pads called "sink_0", because it failed to parse "%d" as integer and
used 0 instead then.

Instead validate that parsing was actually successful and also don't
even try to parse if the requested pad name contains a '%'.
This commit is contained in:
Sebastian Dröge 2019-07-08 19:09:03 +03:00 committed by Sebastian Dröge
parent 35294f365e
commit 09909d37bd

View file

@ -1680,14 +1680,22 @@ gst_aggregator_default_create_new_pad (GstAggregator * self,
GST_OBJECT_LOCK (self);
if (req_name == NULL || strlen (req_name) < 6
|| !g_str_has_prefix (req_name, "sink_")) {
|| !g_str_has_prefix (req_name, "sink_")
|| strrchr (req_name, '%') != NULL) {
/* no name given when requesting the pad, use next available int */
serial = ++priv->max_padserial;
} else {
gchar *endptr = NULL;
/* parse serial number from requested padname */
serial = g_ascii_strtoull (&req_name[5], NULL, 10);
if (serial > priv->max_padserial)
priv->max_padserial = serial;
serial = g_ascii_strtoull (&req_name[5], &endptr, 10);
if (endptr != NULL && *endptr == '\0') {
if (serial > priv->max_padserial) {
priv->max_padserial = serial;
}
} else {
serial = ++priv->max_padserial;
}
}
name = g_strdup_printf ("sink_%u", serial);