From e173302f6498c0e174af1de360b80d33361b099a Mon Sep 17 00:00:00 2001 From: Oz Date: Sun, 22 Oct 2023 10:37:17 +0200 Subject: [PATCH] [Test] Fix warnings from PVS-Studio --- src/internal/cbufferoutstream.cpp | 2 +- src/internal/cfixedbufferoutstream.cpp | 9 +++++---- src/internal/util.hpp | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/internal/cbufferoutstream.cpp b/src/internal/cbufferoutstream.cpp index 3b9e5ee4..173f5f19 100644 --- a/src/internal/cbufferoutstream.cpp +++ b/src/internal/cbufferoutstream.cpp @@ -61,7 +61,7 @@ STDMETHODIMP CBufferOutStream::Write( const void* data, UInt32 size, UInt32* pro } auto oldPos = ( mCurrentPosition - mBuffer.begin() ); - const size_t newPos = static_cast< size_t >( oldPos ) + size; + const size_t newPos = static_cast< size_t >( oldPos ) + static_cast< size_t >( size ); if ( newPos > mBuffer.size() ) { try { mBuffer.resize( newPos ); diff --git a/src/internal/cfixedbufferoutstream.cpp b/src/internal/cfixedbufferoutstream.cpp index 6c310011..7c8bc639 100644 --- a/src/internal/cfixedbufferoutstream.cpp +++ b/src/internal/cfixedbufferoutstream.cpp @@ -77,12 +77,12 @@ STDMETHODIMP CFixedBufferOutStream::Write( const void* data, UInt32 size, UInt32 return E_FAIL; } - uint32_t writeSize = size; + auto writeSize = static_cast< size_t >( size ); size_t remainingSize = mBufferSize - mCurrentPosition; // The Seek method ensures mCurrentPosition < mBufferSize. - if ( size > remainingSize ) { + if ( writeSize > remainingSize ) { /* Writing only to the remaining part of the output buffer! * Note: since size is an uint32_t, and size >= mBufferSize - mCurrentPosition, the cast is safe. */ - writeSize = clamp_cast< uint32_t >( remainingSize ); + writeSize = remainingSize; } const auto* byteData = static_cast< const byte_t* >( data ); //-V2571 @@ -96,7 +96,8 @@ STDMETHODIMP CFixedBufferOutStream::Write( const void* data, UInt32 size, UInt32 mCurrentPosition += writeSize; if ( processedSize != nullptr ) { - *processedSize = writeSize; + // Note: writeSize is not greater than size, which is UInt32, so the cast is safe. + *processedSize = static_cast< UInt32 >( writeSize ); } return S_OK; diff --git a/src/internal/util.hpp b/src/internal/util.hpp index 0b354f7f..6957536f 100644 --- a/src/internal/util.hpp +++ b/src/internal/util.hpp @@ -45,6 +45,8 @@ inline auto seek_to_offset( uint64_t& position, int64_t offset ) noexcept -> HRE return E_INVALIDARG; } position = seekPosition; + } else { + // No action needed } return S_OK; }