Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1098)

Unified Diff: net/base/ip_address_number.cc

Issue 1692353002: Make IP Address related functions return the empty string when used on an invalid address. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/ip_address_number.h ('k') | net/base/ip_address_number_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/ip_address_number.cc
diff --git a/net/base/ip_address_number.cc b/net/base/ip_address_number.cc
index 1e44b7d3b1ebcc74873fa762eb0ced94411c188d..80cd7e92b3217b9a62924e791f71a7f88469ca9d 100644
--- a/net/base/ip_address_number.cc
+++ b/net/base/ip_address_number.cc
@@ -102,8 +102,6 @@ std::string IPAddressToString(const uint8_t* address, size_t address_len) {
url::AppendIPv4Address(address, &output);
} else if (address_len == kIPv6AddressSize) {
url::AppendIPv6Address(address, &output);
- } else {
- CHECK(false) << "Invalid IP address with length: " << address_len;
}
martijnc 2016/02/17 21:46:55 Also simplified this. The else clause wasn't neces
output.Complete();
@@ -114,6 +112,8 @@ std::string IPAddressToStringWithPort(const uint8_t* address,
size_t address_len,
uint16_t port) {
std::string address_str = IPAddressToString(address, address_len);
+ if (address_str.empty())
+ return address_str;
if (address_len == kIPv6AddressSize) {
// Need to bracket IPv6 addresses since they contain colons.
@@ -123,17 +123,16 @@ std::string IPAddressToStringWithPort(const uint8_t* address,
}
std::string IPAddressToString(const IPAddressNumber& addr) {
- return IPAddressToString(&addr.front(), addr.size());
+ return IPAddressToString(addr.data(), addr.size());
}
std::string IPAddressToStringWithPort(const IPAddressNumber& addr,
uint16_t port) {
- return IPAddressToStringWithPort(&addr.front(), addr.size(), port);
+ return IPAddressToStringWithPort(addr.data(), addr.size(), port);
}
std::string IPAddressToPackedString(const IPAddressNumber& addr) {
- return std::string(reinterpret_cast<const char *>(&addr.front()),
- addr.size());
+ return std::string(reinterpret_cast<const char*>(addr.data()), addr.size());
}
bool ParseURLHostnameToNumber(const std::string& hostname,
« no previous file with comments | « net/base/ip_address_number.h ('k') | net/base/ip_address_number_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698