From 08002f0497f53c44d396f470d44650825f072ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Sun, 5 Nov 2023 04:16:07 +0100 Subject: [PATCH] spa: libcamera: get rid of an unnecessary `snprintf()` call Simply use the returned string for populating the spa_dict instead of doing a copy into a fixed size buffer on the stack. --- spa/plugins/libcamera/libcamera-device.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spa/plugins/libcamera/libcamera-device.cpp b/spa/plugins/libcamera/libcamera-device.cpp index 70b7c144a..0abf2f619 100644 --- a/spa/plugins/libcamera/libcamera-device.cpp +++ b/spa/plugins/libcamera/libcamera-device.cpp @@ -106,7 +106,7 @@ static int emit_info(struct impl *impl, bool full) uint32_t n_items = 0; struct spa_device_info info; struct spa_param_info params[2]; - char path[256], model[256], name[256], devices_str[128]; + char path[256], name[256], devices_str[128]; struct spa_strbuf buf; info = SPA_DEVICE_INFO_INIT(); @@ -123,9 +123,10 @@ static int emit_info(struct impl *impl, bool full) if (auto location = cameraLoc(impl->camera.get())) ADD_ITEM(SPA_KEY_API_LIBCAMERA_LOCATION, location); - snprintf(model, sizeof(model), "%s", cameraModel(impl->camera.get()).c_str()); - ADD_ITEM(SPA_KEY_DEVICE_PRODUCT_NAME, model); - ADD_ITEM(SPA_KEY_DEVICE_DESCRIPTION, model); + const auto model = cameraModel(impl->camera.get()); + ADD_ITEM(SPA_KEY_DEVICE_PRODUCT_NAME, model.c_str()); + ADD_ITEM(SPA_KEY_DEVICE_DESCRIPTION, model.c_str()); + snprintf(name, sizeof(name), "libcamera_device.%s", impl->device_id.c_str()); ADD_ITEM(SPA_KEY_DEVICE_NAME, name);