From 22eea89e93db42ad2f1a6e6e61eba78188a2f614 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Fri, 7 Mar 2025 12:06:59 +0100 Subject: [PATCH] MT#59962 Coverity Scan: Division or modulo by float zero (AmAudio) Fixes: Division or modulo by float zero (DIVIDE_BY_ZERO). divide_by_zero: In function call resampleOutput, division by expression mixer_sample_rate which may be zero has undefined behavior. Change-Id: I7f7b8738eb643499dfbf5e830f3904c62ed02b45 --- core/AmAudio.cpp | 3 +++ core/AmConferenceChannel.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/AmAudio.cpp b/core/AmAudio.cpp index 4856bb82..e9b76c79 100644 --- a/core/AmAudio.cpp +++ b/core/AmAudio.cpp @@ -469,6 +469,9 @@ unsigned int AmAudio::resampleOutput(unsigned char* buffer, unsigned int s, int unsigned int AmAudio::resample(AmResamplingState& rstate, unsigned char* buffer, unsigned int s, int input_sample_rate, int output_sample_rate) { + if (!input_sample_rate) + return 0; + return rstate.resample((unsigned char*) buffer, s, ((double) output_sample_rate) / ((double) input_sample_rate)); } diff --git a/core/AmConferenceChannel.cpp b/core/AmConferenceChannel.cpp index 928fbf48..3b2f86a5 100644 --- a/core/AmConferenceChannel.cpp +++ b/core/AmConferenceChannel.cpp @@ -97,7 +97,7 @@ int AmConferenceChannel::get(unsigned long long system_ts, unsigned char* buffer size = resampleOutput(buffer,size,mixer_sample_rate,output_sample_rate); mixer->unlock(); - return size; + return size; /* will be zero if `mixer_sample_rate` isn't set */ } ChannelWritingFile::ChannelWritingFile(const char* path)