Commit b3e20313 authored by David Benjamin's avatar David Benjamin Committed by Commit Bot

Don't call std::string::back() on empty strings

Found with _LIBCPP_DEBUG=0.

Bug: 923166
Change-Id: Ifdb0be8031bc95f05ff3d67876407569bac0e106
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1891235
Commit-Queue: David Benjamin <davidben@chromium.org>
Commit-Queue: Eric Orth <ericorth@chromium.org>
Auto-Submit: David Benjamin <davidben@chromium.org>
Reviewed-by: default avatarEric Orth <ericorth@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711037}
parent 91588a9c
...@@ -162,7 +162,7 @@ bool ResemblesMulticastDNSName(const std::string& hostname) { ...@@ -162,7 +162,7 @@ bool ResemblesMulticastDNSName(const std::string& hostname) {
const char kSuffix[] = ".local."; const char kSuffix[] = ".local.";
const size_t kSuffixLen = sizeof(kSuffix) - 1; const size_t kSuffixLen = sizeof(kSuffix) - 1;
const size_t kSuffixLenTrimmed = kSuffixLen - 1; const size_t kSuffixLenTrimmed = kSuffixLen - 1;
if (hostname.back() == '.') { if (!hostname.empty() && hostname.back() == '.') {
return hostname.size() > kSuffixLen && return hostname.size() > kSuffixLen &&
!hostname.compare(hostname.size() - kSuffixLen, kSuffixLen, kSuffix); !hostname.compare(hostname.size() - kSuffixLen, kSuffixLen, kSuffix);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment