mirror of https://github.com/nodejs/node.git
crypto: use ByteSource::Builder in To*Copy
Avoid manual calls to MallocOpenSSL in ArrayBufferOrViewContents and use the new ByteSource::Builder instead. Refs: https://github.com/nodejs/node/pull/43202 PR-URL: https://github.com/nodejs/node/pull/43477 Reviewed-By: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
parent
c7a0b141b6
commit
42ad967d68
|
@ -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<void>(), data(), size());
|
||||
buf.data<char>()[size()] = 0;
|
||||
return std::move(buf).release(size());
|
||||
}
|
||||
|
||||
template <typename M>
|
||||
|
|
Loading…
Reference in New Issue