Skip to content

Commit

Permalink
[Test] Fix warnings from PVS-Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Oct 22, 2023
1 parent dbed9c8 commit e173302
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/internal/cbufferoutstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
9 changes: 5 additions & 4 deletions src/internal/cfixedbufferoutstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/internal/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit e173302

Please sign in to comment.