diff --git a/rtc_base/http_common.cc b/rtc_base/http_common.cc index 88639a7c70..5ac222f468 100644 --- a/rtc_base/http_common.cc +++ b/rtc_base/http_common.cc @@ -282,7 +282,7 @@ HttpAuthResult HttpAuthenticate(const char* challenge, // std::string decoded = username + ":" + password; size_t len = username.size() + password.GetLength() + 2; char* sensitive = new char[len]; - size_t pos = strcpyn(sensitive, len, username.data(), username.size()); + size_t pos = strcpyn(sensitive, len, username); pos += strcpyn(sensitive + pos, len - pos, ":"); password.CopyTo(sensitive + pos, true); @@ -322,9 +322,9 @@ HttpAuthResult HttpAuthenticate(const char* challenge, // std::string A1 = username + ":" + realm + ":" + password; size_t len = username.size() + realm.size() + password.GetLength() + 3; char* sensitive = new char[len]; // A1 - size_t pos = strcpyn(sensitive, len, username.data(), username.size()); + size_t pos = strcpyn(sensitive, len, username); pos += strcpyn(sensitive + pos, len - pos, ":"); - pos += strcpyn(sensitive + pos, len - pos, realm.c_str()); + pos += strcpyn(sensitive + pos, len - pos, realm); pos += strcpyn(sensitive + pos, len - pos, ":"); password.CopyTo(sensitive + pos, true); diff --git a/rtc_base/string_utils.cc b/rtc_base/string_utils.cc index e8c13464bd..b93e615705 100644 --- a/rtc_base/string_utils.cc +++ b/rtc_base/string_utils.cc @@ -14,20 +14,15 @@ namespace rtc { -size_t strcpyn(char* buffer, - size_t buflen, - const char* source, - size_t srclen /* = SIZE_UNKNOWN */) { +size_t strcpyn(char* buffer, size_t buflen, absl::string_view source) { if (buflen <= 0) return 0; - if (srclen == SIZE_UNKNOWN) { - srclen = strlen(source); - } + size_t srclen = source.length(); if (srclen >= buflen) { srclen = buflen - 1; } - memcpy(buffer, source, srclen); + memcpy(buffer, source.data(), srclen); buffer[srclen] = 0; return srclen; } diff --git a/rtc_base/string_utils.h b/rtc_base/string_utils.h index a9cdd61a7b..d062675a94 100644 --- a/rtc_base/string_utils.h +++ b/rtc_base/string_utils.h @@ -51,10 +51,7 @@ struct AbslStringViewCmp { }; // Safe version of strncpy that always nul-terminate. -size_t strcpyn(char* buffer, - size_t buflen, - const char* source, - size_t srclen = SIZE_UNKNOWN); +size_t strcpyn(char* buffer, size_t buflen, absl::string_view source); /////////////////////////////////////////////////////////////////////////////// // UTF helpers (Windows only)