From a82ecdfa8a29c9addeb6724bd698a32db407d4c0 Mon Sep 17 00:00:00 2001 From: Steve Lhomme <robux4@ycbcr.xyz> Date: Tue, 6 Sep 2022 12:58:57 +0200 Subject: [PATCH] decklink: simplify the mode string usage The mode can never be NULL. If it was, autodetect is set to false so we never reach this code. We can optimize the strlen() calls with a single strnlen() call that will only test up to 5 chars to check we don't have 3 or 4 chars. --- modules/access/decklink.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/access/decklink.cpp b/modules/access/decklink.cpp index aa43dade5fe6..2144047b6829 100644 --- a/modules/access/decklink.cpp +++ b/modules/access/decklink.cpp @@ -648,8 +648,9 @@ static int Open(vlc_object_t *p_this) /* Enable a random format, we will reconfigure on format detection */ u.id = bmdModeHD1080p2997; } else { - if (!mode || strlen(mode) < 3 || strlen(mode) > 4) { - msg_Err(demux, "Invalid mode: \'%s\'", mode ? mode : ""); + size_t min_size = strnlen(mode, 4+1); + if (min_size < 3 || min_size > 4) { + msg_Err(demux, "Invalid mode: \'%s\'", mode); free(mode); goto finish; } -- GitLab