1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:17:35 +00:00

Everywhere: Port to String::copy_characters_to_buffer()

This commit is contained in:
Sergey Bugaev 2020-08-25 17:32:01 +03:00 committed by Andreas Kling
parent be6cce5530
commit 852454746e
8 changed files with 39 additions and 18 deletions

View file

@ -112,13 +112,12 @@ bool Socket::connect(const SocketAddress& address)
sockaddr_un saddr;
saddr.sun_family = AF_LOCAL;
auto dest_address = address.to_string();
if (dest_address.length() >= sizeof(saddr.sun_path)) {
bool fits = dest_address.copy_characters_to_buffer(saddr.sun_path, sizeof(saddr.sun_path));
if (!fits) {
fprintf(stderr, "Core::Socket: Failed to connect() to %s: Path is too long!\n", dest_address.characters());
errno = EINVAL;
return false;
}
strcpy(saddr.sun_path, address.to_string().characters());
m_destination_address = address;
return common_connect((const sockaddr*)&saddr, sizeof(saddr));

View file

@ -87,10 +87,9 @@ public:
ASSERT(type() == Type::Local);
sockaddr_un address;
address.sun_family = AF_LOCAL;
if (m_local_address.length() >= sizeof(address.sun_path)) {
bool fits = m_local_address.copy_characters_to_buffer(address.sun_path, sizeof(address.sun_path));
if (!fits)
return {};
}
strcpy(address.sun_path, m_local_address.characters());
return address;
}