From b7c8a6faa5bdd59462c3f47c8d4259ca6bb9d2af Mon Sep 17 00:00:00 2001 From: Christoph Haag Date: Tue, 14 Dec 2021 14:58:09 +0100 Subject: [PATCH] d/ht_ctrl_emu: work around truncation warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ../src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp: In function ‘int cemu_devices_create(xrt_device*, xrt_device*, xrt_device**)’: ../src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp:439:102: warning: ‘ Left Hand’ directive output may be truncated writing 10 bytes into a region of size between 1 and 256 [-Wformat-truncation=] 439 | int ret = snprintf(cemud[i]->base.str, XRT_DEVICE_NAME_LEN, i ? "%s Right Hand" : "%s Left Hand", hands->str); | ^~~~~~~~~~ ../src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp:439:35: note: ‘snprintf’ output between 11 and 266 bytes into a destination of size 256 439 | int ret = snprintf(cemud[i]->base.str, XRT_DEVICE_NAME_LEN, i ? "%s Right Hand" : "%s Left Hand", hands->str); | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp:439:84: warning: ‘ Right Hand’ directive output may be truncated writing 11 bytes into a region of size between 1 and 256 [-Wformat-truncation=] 439 | int ret = snprintf(cemud[i]->base.str, XRT_DEVICE_NAME_LEN, i ? "%s Right Hand" : "%s Left Hand", hands->str); | ^~~~~~~~~~~ ../src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp:439:35: note: ‘snprintf’ output between 12 and 267 bytes into a destination of size 256 439 | int ret = snprintf(cemud[i]->base.str, XRT_DEVICE_NAME_LEN, i ? "%s Right Hand" : "%s Left Hand", hands->str); | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp b/src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp index 50e8cfbff..961974b80 100644 --- a/src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp +++ b/src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp @@ -436,7 +436,11 @@ cemu_devices_create(struct xrt_device *head, struct xrt_device *hands, struct xr i ? XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER : XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER; //!@todo What should we do with the serial numbers? - snprintf(cemud[i]->base.str, XRT_DEVICE_NAME_LEN, i ? "%s Right Hand" : "%s Left Hand", hands->str); + int ret = + snprintf(cemud[i]->base.str, XRT_DEVICE_NAME_LEN, i ? "%s Right Hand" : "%s Left Hand", hands->str); + if (ret >= 0) { + CEMU_DEBUG(cemud[i], "name truncated: %s", cemud[i]->base.str); + } cemud[i]->ht_input_name = i ? XRT_INPUT_GENERIC_HAND_TRACKING_RIGHT : XRT_INPUT_GENERIC_HAND_TRACKING_LEFT;