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

Unified Diff: net/socket/ssl_client_socket.cc

Issue 798603002: Remove memcpy from SSLClientSocket::SerializeNextProtos. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/ssl_client_socket.cc
diff --git a/net/socket/ssl_client_socket.cc b/net/socket/ssl_client_socket.cc
index f6b9b895fa853410be2c8ed7d6fb9a3ff39ab726..8d76f4b9d3cb7270489b14a96ef937081d90f4ff 100644
--- a/net/socket/ssl_client_socket.cc
+++ b/net/socket/ssl_client_socket.cc
@@ -236,9 +236,7 @@ bool SSLClientSocket::IsChannelIDEnabled(
// static
std::vector<uint8_t> SSLClientSocket::SerializeNextProtos(
const NextProtoVector& next_protos) {
- // Do a first pass to determine the total length.
- size_t wire_length = 0;
- std::vector<std::string> next_proto_strings;
+ std::vector<uint8_t> wire_protos;
for (const NextProto next_proto : next_protos) {
const std::string proto = NextProtoToString(next_proto);
if (proto.size() > 255) {
@@ -249,22 +247,11 @@ std::vector<uint8_t> SSLClientSocket::SerializeNextProtos(
LOG(WARNING) << "Ignoring empty NPN/ALPN protocol";
continue;
}
- next_proto_strings.push_back(proto);
- wire_length += proto.size();
- wire_length++;
- }
-
- // Allocate memory for the result and fill it in.
- std::vector<uint8_t> wire_protos;
- wire_protos.reserve(wire_length);
- for (const std::string& proto : next_proto_strings) {
wire_protos.push_back(proto.size());
- // TODO(bnc): Rewrite.
- wire_protos.resize(wire_protos.size() + proto.size());
- memcpy(&wire_protos[wire_protos.size() - proto.size()], proto.data(),
- proto.size());
+ for (const auto ch : proto) {
Ryan Hamilton 2014/12/11 19:58:41 s/auto/char/ (I assume it's a char?)
Bence 2014/12/12 13:22:25 You are right, the standard requires it in Section
+ wire_protos.push_back(static_cast<uint8_t>(ch));
+ }
}
- DCHECK_EQ(wire_protos.size(), wire_length);
return wire_protos;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698