From 2c07fd5369ae31221389e724ddc2ae409ccfad7b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 3 Jul 2020 11:21:57 +0200 Subject: acp-device: improve %f substitution with card_id --- spa/plugins/alsa/alsa-acp-device.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/spa/plugins/alsa/alsa-acp-device.c b/spa/plugins/alsa/alsa-acp-device.c index 397fca6b..ee5dc58d 100644 --- a/spa/plugins/alsa/alsa-acp-device.c +++ b/spa/plugins/alsa/alsa-acp-device.c @@ -128,7 +128,7 @@ static int emit_node(struct impl *this, struct acp_device *dev) char card_id[16], *p; struct spa_device_object_info info; struct acp_card *card = this->card; - const char *stream; + const char *stream, *devstr;; info = SPA_DEVICE_OBJECT_INFO_INIT(); info.type = SPA_TYPE_INTERFACE_Node; @@ -147,10 +147,16 @@ static int emit_node(struct impl *this, struct acp_device *dev) items = alloca(n_items * sizeof(*items)); snprintf(card_id, sizeof(card), "%d", card->index); - snprintf(device_name, sizeof(device_name), "%s", dev->device_strings[0]); - p = strstr(device_name, "%f"); - if (p) - snprintf(p, 4, "%d%s", card->index, p+2); + + devstr = dev->device_strings[0]; + p = strstr(devstr, "%f"); + if (p) { + snprintf(device_name, sizeof(device_name), "%.*s%d%s", + (int)SPA_PTRDIFF(p, devstr), devstr, + card->index, p+2); + } else { + snprintf(device_name, sizeof(device_name), "%s", devstr); + } snprintf(path, sizeof(path), "alsa:pcm:%s:%s:%s", card_id, device_name, stream); items[0] = SPA_DICT_ITEM_INIT(SPA_KEY_OBJECT_PATH, path); items[1] = SPA_DICT_ITEM_INIT(SPA_KEY_API_ALSA_PATH, device_name); -- cgit v1.2.3