From 33a6912778bc0405168c4c16e777d45ee4bad009 Mon Sep 17 00:00:00 2001 From: sukibaby <163092272+sukibaby@users.noreply.github.com> Date: Tue, 6 May 2025 06:12:55 -0700 Subject: [PATCH] Code scanning alert #487 "Multiplication result converted to larger type" My own fix, not auto-generated. m_iChannels is implicitly promoted to size_t. --- src/RageSoundReader_Chain.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/RageSoundReader_Chain.cpp b/src/RageSoundReader_Chain.cpp index 2c8d968b73..60af9e4095 100644 --- a/src/RageSoundReader_Chain.cpp +++ b/src/RageSoundReader_Chain.cpp @@ -341,11 +341,14 @@ int RageSoundReader_Chain::Read( float *pBuffer, int iFrames ) return iFrames; } + // Note: this is only safe because we know pBuffer is not nullptr + // and iFrames and m_iChannels are reasonable sizes. if( m_apActiveSounds.empty() ) { /* If we have more sounds ahead of us, pretend we read the entire block, since * there's silence in between. Otherwise, we're at EOF. */ - memset( pBuffer, 0, iFrames * m_iChannels * sizeof(float) ); + size_t pBufferSize = static_cast(iFrames) * m_iChannels * sizeof(float); + memset( pBuffer, 0, pBufferSize ); m_iCurrentFrame += iFrames; return iFrames; }