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

AK: Migrate IPv6Address::to_deprecated_string() to ::to_string()

Change the name and return type of
`IPv6Address::to_deprecated_string()` to `IPv6Address::to_string()`
with return type `ErrorOr<String>`.

It will now propagate errors that occur when writing to the
StringBuilder.

There are two users of `to_deprecated_string()` that now use
`to_string()`:

1. `Formatted<IPv6Address>`: it now propagates errors.

2. `inet_ntop`: it now sets errno to ENOMEM and returns.
This commit is contained in:
Peter Brottveit Bock 2023-05-30 01:02:45 +02:00 committed by Sam Atkins
parent fdfffe2d8c
commit 49b29332f2
3 changed files with 30 additions and 22 deletions

View file

@ -27,8 +27,13 @@ char const* inet_ntop(int af, void const* src, char* dst, socklen_t len)
errno = ENOSPC;
return nullptr;
}
auto str = IPv6Address(((in6_addr const*)src)->s6_addr).to_deprecated_string();
if (!str.copy_characters_to_buffer(dst, len)) {
auto str_or_error = IPv6Address(((in6_addr const*)src)->s6_addr).to_string();
if (str_or_error.is_error()) {
errno = ENOMEM;
return nullptr;
}
auto str = str_or_error.release_value();
if (!str.bytes_as_string_view().copy_characters_to_buffer(dst, len)) {
errno = ENOSPC;
return nullptr;
}