Skip to content

Commit d14d479

Browse files
committed
crypto: use ByteSource::Builder in To*Copy
Refs: #43202
1 parent a36a546 commit d14d479

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/crypto/crypto_util.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -747,19 +747,17 @@ class ArrayBufferOrViewContents {
747747

748748
inline ByteSource ToCopy() const {
749749
if (size() == 0) return ByteSource();
750-
char* buf = MallocOpenSSL<char>(size());
751-
CHECK_NOT_NULL(buf);
752-
memcpy(buf, data(), size());
753-
return ByteSource::Allocated(buf, size());
750+
ByteSource::Builder buf(size());
751+
memcpy(buf.data<void>(), data(), size());
752+
return std::move(buf).release();
754753
}
755754

756755
inline ByteSource ToNullTerminatedCopy() const {
757756
if (size() == 0) return ByteSource();
758-
char* buf = MallocOpenSSL<char>(size() + 1);
759-
CHECK_NOT_NULL(buf);
760-
buf[size()] = 0;
761-
memcpy(buf, data(), size());
762-
return ByteSource::Allocated(buf, size());
757+
ByteSource::Builder buf(size() + 1);
758+
memcpy(buf.data<char>(), data(), size());
759+
buf.data<char>()[size()] = 0;
760+
return std::move(buf).release();
763761
}
764762

765763
template <typename M>

0 commit comments

Comments
 (0)