2
0
mirror of https://github.com/boostorg/asio.git synced 2026-01-27 18:42:07 +00:00

Don't call memcpy with length 0, to avoid passing null pointers.

This commit is contained in:
Christopher Kohlhoff
2017-12-02 08:28:39 +11:00
parent f8a0469702
commit 78df0763bf
3 changed files with 6 additions and 3 deletions

View File

@@ -1921,7 +1921,8 @@ inline std::size_t buffer_copy_1(const mutable_buffer& target,
std::size_t target_size = target.size();
std::size_t source_size = source.size();
std::size_t n = target_size < source_size ? target_size : source_size;
memcpy(target.data(), source.data(), n);
if (n > 0)
memcpy(target.data(), source.data(), n);
return n;
}

View File

@@ -95,7 +95,8 @@ void endpoint::init(const void* sock_addr,
using namespace std; // For memset and memcpy.
memset(&data_.generic, 0, sizeof(boost::asio::detail::sockaddr_storage_type));
memcpy(&data_.generic, sock_addr, sock_addr_size);
if (sock_addr_size > 0)
memcpy(&data_.generic, sock_addr, sock_addr_size);
size_ = sock_addr_size;
protocol_ = sock_protocol;

View File

@@ -109,7 +109,8 @@ void endpoint::init(const char* path_name, std::size_t path_length)
using namespace std; // For memcpy.
data_.local = boost::asio::detail::sockaddr_un_type();
data_.local.sun_family = AF_UNIX;
memcpy(data_.local.sun_path, path_name, path_length);
if (path_length > 0)
memcpy(data_.local.sun_path, path_name, path_length);
path_length_ = path_length;
// NUL-terminate normal path names. Names that start with a NUL are in the