1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Better handling of disconnects, code cleanup

This commit is contained in:
Ivan Savenko
2024-02-02 15:32:06 +02:00
parent 03fcfe3392
commit f97ffd8e9a
14 changed files with 76 additions and 91 deletions

View File

@@ -17,7 +17,7 @@ int CMemorySerializer::read(std::byte * data, unsigned size)
if(buffer.size() < readPos + size)
throw std::runtime_error(boost::str(boost::format("Cannot read past the buffer (accessing index %d, while size is %d)!") % (readPos + size - 1) % buffer.size()));
std::memcpy(data, buffer.data() + readPos, size);
std::copy_n(buffer.data() + readPos, size, data);
readPos += size;
return size;
}
@@ -26,7 +26,7 @@ int CMemorySerializer::write(const std::byte * data, unsigned size)
{
auto oldSize = buffer.size(); //and the pos to write from
buffer.resize(oldSize + size);
std::memcpy(buffer.data() + oldSize, data, size);
std::copy_n(data, size, buffer.data() + oldSize);
return size;
}