yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

fsp_srv: Respect write length in Write()

Previously we were just copying the data whole-sale, even if the length
was less than the total data size. This effectively makes the
actual_data vector useless, which is likely not intended.

Instead, amend this to only copy the given length amount of data.

At the same time, we can avoid zeroing out the data before using it by
passing iterators to the constructor instead of a size.
This commit is contained in:
Lioncash 2018-07-19 09:53:35 -04:00
parent cd4fca8447
commit d6e9b96e2f
1 changed files with 5 additions and 4 deletions

View File

@ -3,6 +3,8 @@
// Refer to the license.txt file included.
#include <cinttypes>
#include <utility>
#include "common/logging/log.h"
#include "common/string_util.h"
#include "core/core.h"
@ -133,17 +135,16 @@ private:
return;
}
std::vector<u8> data = ctx.ReadBuffer();
std::vector<u8> actual_data(length);
const std::vector<u8> data = ctx.ReadBuffer();
ASSERT_MSG(
data.size() <= length,
"Attempting to write more data than requested (requested={:016X}, actual={:016X}).",
length, data.size());
std::copy(data.begin(), data.end(), actual_data.begin());
// Write the data to the Storage backend
auto written = backend->WriteBytes(data, offset);
std::vector<u8> actual_data(data.begin(), data.begin() + length);
const auto written = backend->WriteBytes(std::move(actual_data), offset);
ASSERT_MSG(written == length,
"Could not write all bytes to file (requested={:016X}, actual={:016X}).", length,