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

This commit is contained in:
Christopher Kohlhoff 2017-11-27 09:10:29 +11:00
parent ede4e7597d
commit c80c1cbd5c
3 changed files with 6 additions and 3 deletions

View File

@ -1920,7 +1920,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

@ -94,7 +94,8 @@ void endpoint::init(const void* sock_addr,
using namespace std; // For memset and memcpy.
memset(&data_.generic, 0, sizeof(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

@ -108,7 +108,8 @@ void endpoint::init(const char* path_name, std::size_t path_length)
using namespace std; // For memcpy.
data_.local = 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