summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Holthuis <jan.holthuis@ruhr-uni-bochum.de>2020-11-24 16:10:59 +0100
committerJan Holthuis <jan.holthuis@ruhr-uni-bochum.de>2020-11-24 18:11:12 +0100
commitf543b52eb56e2fea11b73a00ad3e911f14e98817 (patch)
treec802442435b76cecf3970e8018820006295da297
parente6433e3176f15242611e7700bfae05b41799988f (diff)
EncoderMP3: Fix conversion warnings on Windows
Fixes: src\encoder\encodermp3.cpp(122): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data src\encoder\encodermp3.cpp(125): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
-rw-r--r--src/encoder/encodermp3.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/encoder/encodermp3.cpp b/src/encoder/encodermp3.cpp
index f938bb3411..d8053ea27d 100644
--- a/src/encoder/encodermp3.cpp
+++ b/src/encoder/encodermp3.cpp
@@ -118,14 +118,17 @@ void EncoderMp3::flush() {
// end encoded audio to broadcast or file
m_pCallback->write(nullptr, m_bufferOut, 0, rc);
- // Write the lame/xing header.
- rc = lame_get_lametag_frame(m_lameFlags, m_bufferOut, m_bufferOutSize);
- if (rc != m_bufferOutSize) {
- bufferOutGrow(rc);
- rc = lame_get_lametag_frame(m_lameFlags, m_bufferOut, m_bufferOutSize);
+ // `lame_get_lametag_frame` returns the number of bytes copied into buffer,
+ // or the required buffer size, if the provided buffer is too small.
+ // Function failed, if the return value is larger than `m_bufferOutSize`!
+ size_t numBytes = lame_get_lametag_frame(m_lameFlags, m_bufferOut, m_bufferOutSize);
+ if (numBytes > static_cast<size_t>(m_bufferOutSize)) {
+ bufferOutGrow(numBytes);
+ numBytes = lame_get_lametag_frame(m_lameFlags, m_bufferOut, m_bufferOutSize);
}
+ // Write the lame/xing header.
m_pCallback->seek(0);
- m_pCallback->write(nullptr, m_bufferOut, 0, rc);
+ m_pCallback->write(nullptr, m_bufferOut, 0, static_cast<int>(numBytes));
}
void EncoderMp3::encodeBuffer(const CSAMPLE *samples, const int size) {