Commit debbbb37 authored by bnc's avatar bnc Committed by Commit bot

Remove memcpy from SSLClientSocket::SerializeNextProtos.

Review URL: https://codereview.chromium.org/798603002

Cr-Commit-Position: refs/heads/master@{#308141}
parent b1b01c57
...@@ -236,9 +236,7 @@ bool SSLClientSocket::IsChannelIDEnabled( ...@@ -236,9 +236,7 @@ bool SSLClientSocket::IsChannelIDEnabled(
// static // static
std::vector<uint8_t> SSLClientSocket::SerializeNextProtos( std::vector<uint8_t> SSLClientSocket::SerializeNextProtos(
const NextProtoVector& next_protos) { const NextProtoVector& next_protos) {
// Do a first pass to determine the total length. std::vector<uint8_t> wire_protos;
size_t wire_length = 0;
std::vector<std::string> next_proto_strings;
for (const NextProto next_proto : next_protos) { for (const NextProto next_proto : next_protos) {
const std::string proto = NextProtoToString(next_proto); const std::string proto = NextProtoToString(next_proto);
if (proto.size() > 255) { if (proto.size() > 255) {
...@@ -249,22 +247,11 @@ std::vector<uint8_t> SSLClientSocket::SerializeNextProtos( ...@@ -249,22 +247,11 @@ std::vector<uint8_t> SSLClientSocket::SerializeNextProtos(
LOG(WARNING) << "Ignoring empty NPN/ALPN protocol"; LOG(WARNING) << "Ignoring empty NPN/ALPN protocol";
continue; 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()); wire_protos.push_back(proto.size());
// TODO(bnc): Rewrite. for (const char ch : proto) {
wire_protos.resize(wire_protos.size() + proto.size()); wire_protos.push_back(static_cast<uint8_t>(ch));
memcpy(&wire_protos[wire_protos.size() - proto.size()], proto.data(), }
proto.size());
} }
DCHECK_EQ(wire_protos.size(), wire_length);
return wire_protos; return wire_protos;
} }
......
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