From 0ac3e6fd5bf4653895b28fb5fb692177d3bb4be6 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 22 Feb 2021 20:40:22 -0500 Subject: [PATCH] remove unneeded strlen --- src/zm_ffmpeg.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index a0131d75f..6ff053c34 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -64,11 +64,15 @@ void log_libav_callback(void *ptr, int level, const char *fmt, va_list vargs) { if ( log ) { char logString[8192]; - vsnprintf(logString, sizeof(logString)-1, fmt, vargs); - int length = strlen(logString); - // ffmpeg logs have a carriage return, so replace it with terminator - logString[length-1] = 0; - log->logPrint(false, __FILE__, __LINE__, log_level, logString); + int length = vsnprintf(logString, sizeof(logString)-1, fmt, vargs); + if ( length > 0 ) { + if ( static_cast(length) > sizeof(logString)-1 ) length = sizeof(logString)-1; + // ffmpeg logs have a carriage return, so replace it with terminator + logString[length-1] = 0; + log->logPrint(false, __FILE__, __LINE__, log_level, logString); + } else { + log->logPrint(false, __FILE__, __LINE__, AV_LOG_ERROR, "Can't encode log from av. fmt was %s", fmt); + } } }