Codechange: replace memcpy with std::copy_n
This commit is contained in:
@@ -259,7 +259,7 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *
|
||||
if (sockets == nullptr) {
|
||||
this->address_length = (int)runp->ai_addrlen;
|
||||
assert(sizeof(this->address) >= runp->ai_addrlen);
|
||||
memcpy(&this->address, runp->ai_addr, runp->ai_addrlen);
|
||||
std::copy_n(reinterpret_cast<const std::byte *>(runp->ai_addr), runp->ai_addrlen, reinterpret_cast<std::byte *>(&this->address));
|
||||
#ifdef __EMSCRIPTEN__
|
||||
/* Emscripten doesn't zero sin_zero, but as we compare addresses
|
||||
* to see if they are the same address, we need them to be zero'd.
|
||||
|
||||
@@ -58,11 +58,11 @@ public:
|
||||
* @param address The IP address with port.
|
||||
* @param address_length The length of the address.
|
||||
*/
|
||||
NetworkAddress(sockaddr *address, int address_length) :
|
||||
NetworkAddress(const sockaddr *address, int address_length) :
|
||||
address_length(address_length),
|
||||
resolved(address_length != 0)
|
||||
{
|
||||
memcpy(&this->address, address, address_length);
|
||||
std::copy_n(reinterpret_cast<const std::byte *>(address), address_length, reinterpret_cast<std::byte *>(&this->address));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,7 +48,7 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // Wi
|
||||
|
||||
sockaddr_storage address{};
|
||||
/* iiBroadcast is unusable, because it always seems to be set to 255.255.255.255. */
|
||||
memcpy(&address, &ifo.iiAddress.Address, sizeof(sockaddr));
|
||||
std::copy_n(reinterpret_cast<const std::byte *>(&ifo.iiAddress.Address), sizeof(sockaddr), reinterpret_cast<std::byte *>(&address));
|
||||
reinterpret_cast<sockaddr_in*>(&address)->sin_addr.s_addr = ifo.iiAddress.AddressIn.sin_addr.s_addr | ~ifo.iiNetmask.AddressIn.sin_addr.s_addr;
|
||||
NetworkAddress addr(address, sizeof(sockaddr));
|
||||
if (std::none_of(broadcast->begin(), broadcast->end(), [&addr](NetworkAddress const &elem) -> bool { return elem == addr; })) broadcast->push_back(addr);
|
||||
|
||||
@@ -203,7 +203,7 @@ void HttpThread()
|
||||
|
||||
/* Copy the buffer out of CURL. OnReceiveData() will free it when done. */
|
||||
std::unique_ptr<char[]> buffer = std::make_unique<char[]>(size * nmemb);
|
||||
memcpy(buffer.get(), ptr, size * nmemb);
|
||||
std::copy_n(ptr, size * nmemb, buffer.get());
|
||||
callback->OnReceiveData(std::move(buffer), size * nmemb);
|
||||
|
||||
return size * nmemb;
|
||||
|
||||
Reference in New Issue
Block a user