VolumeWiiCrypted: Use std::min

This commit is contained in:
JosJuice 2015-04-21 11:24:13 +02:00
parent 5c46810a36
commit 405643b902
1 changed files with 7 additions and 6 deletions

View File

@ -4,6 +4,7 @@
#include "DiscIO/VolumeWiiCrypted.h" #include "DiscIO/VolumeWiiCrypted.h"
#include <algorithm>
#include <cstddef> #include <cstddef>
#include <cstring> #include <cstring>
#include <map> #include <map>
@ -87,14 +88,14 @@ bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, bool de
} }
// Copy the decrypted data // Copy the decrypted data
u64 MaxSizeToCopy = BLOCK_DATA_SIZE - data_offset_in_block; u64 copy_size = std::min(_Length, BLOCK_DATA_SIZE - data_offset_in_block);
u64 CopySize = (_Length > MaxSizeToCopy) ? MaxSizeToCopy : _Length; memcpy(_pBuffer, &m_last_decrypted_block_data[data_offset_in_block],
memcpy(_pBuffer, &m_last_decrypted_block_data[data_offset_in_block], (size_t)CopySize); static_cast<size_t>(copy_size));
// Update offsets // Update offsets
_Length -= CopySize; _Length -= copy_size;
_pBuffer += CopySize; _pBuffer += copy_size;
_ReadOffset += CopySize; _ReadOffset += copy_size;
} }
return true; return true;