diff -r e254398fcc7c -r 20ca0a6be175 sources/network/ipaddress.cpp --- a/sources/network/ipaddress.cpp Wed Jan 27 13:17:11 2021 +0200 +++ b/sources/network/ipaddress.cpp Wed Jan 27 14:04:53 2021 +0200 @@ -71,9 +71,9 @@ String val; if (withport == WITH_PORT) - val.sprintf ("%u.%u.%u.%u:%u", octet (0), octet (1), octet (2), octet (3), port); + val = sprintf ("%u.%u.%u.%u:%u", octet (0), octet (1), octet (2), octet (3), port); else - val.sprintf ("%u.%u.%u.%u", octet (0), octet (1), octet (2), octet (3)); + val = sprintf ("%u.%u.%u.%u", octet (0), octet (1), octet (2), octet (3)); return val; } @@ -145,11 +145,11 @@ { unsigned int parts[4]; int colonpos = input.find (":"); - String addressString = colonpos == -1 ? input : input.mid (0, colonpos); + String addressString = colonpos == -1 ? input : mid(input, 0, colonpos); IPAddress value; // Try scanf the IPv4 host first - if (sscanf (addressString, "%u.%u.%u.%u", &parts[0], &parts[1], &parts[2], &parts[3])) + if (sscanf(addressString.data(), "%u.%u.%u.%u", &parts[0], &parts[1], &parts[2], &parts[3])) { for (int i : range(4)) value.set_octet (i, parts[i]); @@ -161,7 +161,13 @@ } if (colonpos != -1) - value.port = (unsigned short) input.mid (colonpos + 1, -1).toInt(); + { + std::optional opt = to_int(mid(input, colonpos + 1, -1).data()); + if (opt.has_value()) + { + value.port = opt.value(); + } + } return value; } @@ -175,7 +181,7 @@ memset (&hints, 0, sizeof hints); hints.ai_family = AF_INET; - if (getaddrinfo (node, nullptr, &hints, &lookup) != 0) + if (getaddrinfo(node.data(), nullptr, &hints, &lookup) != 0) throw StringParseError ("unknown host " + node); IPAddress result;