From b16114fa23f0060910b68d348725db6f8fed4b49 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sun, 29 Oct 2023 18:15:55 -0600 Subject: [PATCH] Replace `std::memcpy` with a more expressive alternative --- examples/voip/Server.cpp | 8 +++----- src/SFML/Network/Packet.cpp | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/examples/voip/Server.cpp b/examples/voip/Server.cpp index 5410fb328..fe891c879 100644 --- a/examples/voip/Server.cpp +++ b/examples/voip/Server.cpp @@ -133,11 +133,9 @@ private: // (so we protect any operation on it with the mutex) { const std::lock_guard lock(m_mutex); - const std::size_t oldSize = m_samples.size(); - m_samples.resize(oldSize + sampleCount); - std::memcpy(&(m_samples[oldSize]), - static_cast(packet.getData()) + 1, - sampleCount * sizeof(std::int16_t)); + const auto* begin = static_cast(packet.getData()) + 1; + const auto* end = begin + sampleCount * sizeof(std::int16_t); + m_samples.insert(m_samples.end(), begin, end); } } else if (id == serverEndOfStream) diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index 0ad0d337d..04d1fe288 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -66,9 +66,9 @@ void Packet::append(const void* data, std::size_t sizeInBytes) { if (data && (sizeInBytes > 0)) { - const std::size_t start = m_data.size(); - m_data.resize(start + sizeInBytes); - std::memcpy(&m_data[start], data, sizeInBytes); + const auto* begin = reinterpret_cast(data); + const auto* end = begin + sizeInBytes; + m_data.insert(m_data.end(), begin, end); } }