From 096ec55c8370052dd9d0547ad1a670b1bdd08f3f Mon Sep 17 00:00:00 2001 From: tytan652 Date: Sun, 12 Dec 2021 16:45:59 +0100 Subject: [PATCH] linux-v4l2: Fix format-truncation warning --- plugins/linux-v4l2/v4l2-output.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/linux-v4l2/v4l2-output.c b/plugins/linux-v4l2/v4l2-output.c index 5ab423fbb..fa4a4005e 100644 --- a/plugins/linux-v4l2/v4l2-output.c +++ b/plugins/linux-v4l2/v4l2-output.c @@ -197,9 +197,14 @@ static bool virtualcam_start(void *data) return false; for (int i = 0; i < n; i++) { - char device[32]; + char device[32] = {0}; - snprintf(device, 32, "/dev/%s", list[i]->d_name); + // Use the return value of snprintf to prevent truncation warning. + int written = snprintf(device, 32, "/dev/%s", list[i]->d_name); + if (written >= 32) + blog(LOG_DEBUG, + "v4l2-output: A format truncation may have occurred." + " This can be ignored since it is quite improbable."); if (try_connect(vcam, device)) { success = true;