Skip to content

Commit

Permalink
crypto: use ByteSource::Builder in To*Copy
Browse files Browse the repository at this point in the history
Refs: #43202
  • Loading branch information
tniessen committed Jun 18, 2022
1 parent a36a546 commit d14d479
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/crypto/crypto_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,19 +747,17 @@ class ArrayBufferOrViewContents {

inline ByteSource ToCopy() const {
if (size() == 0) return ByteSource();
char* buf = MallocOpenSSL<char>(size());
CHECK_NOT_NULL(buf);
memcpy(buf, data(), size());
return ByteSource::Allocated(buf, size());
ByteSource::Builder buf(size());
memcpy(buf.data<void>(), data(), size());
return std::move(buf).release();
}

inline ByteSource ToNullTerminatedCopy() const {
if (size() == 0) return ByteSource();
char* buf = MallocOpenSSL<char>(size() + 1);
CHECK_NOT_NULL(buf);
buf[size()] = 0;
memcpy(buf, data(), size());
return ByteSource::Allocated(buf, size());
ByteSource::Builder buf(size() + 1);
memcpy(buf.data<char>(), data(), size());
buf.data<char>()[size()] = 0;
return std::move(buf).release();
}

template <typename M>
Expand Down

0 comments on commit d14d479

Please sign in to comment.