Skip to content

Commit d50b8a8

Browse files
tniessenRafaelGSS
authored andcommitted
src: remove void* -> char* -> void* casts
When passing the return value of `BackingStore::Data()` as the first or second argument to `memcpy()`, it is unnecessary to cast the returned pointer to `char*`. Refs: #52292 PR-URL: #57791 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent f2cdc98 commit d50b8a8

File tree

6 files changed

+9
-25
lines changed

6 files changed

+9
-25
lines changed

src/crypto/crypto_cipher.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,7 @@ CipherBase::UpdateResult CipherBase::Update(
716716
} else if (static_cast<size_t>(buf_len) != (*out)->ByteLength()) {
717717
std::unique_ptr<BackingStore> old_out = std::move(*out);
718718
*out = ArrayBuffer::NewBackingStore(env()->isolate(), buf_len);
719-
memcpy(static_cast<char*>((*out)->Data()),
720-
static_cast<char*>(old_out->Data()),
721-
buf_len);
719+
memcpy((*out)->Data(), old_out->Data(), buf_len);
722720
}
723721

724722
// When in CCM mode, EVP_CipherUpdate will fail if the authentication tag is
@@ -814,9 +812,7 @@ bool CipherBase::Final(std::unique_ptr<BackingStore>* out) {
814812
} else if (static_cast<size_t>(out_len) != (*out)->ByteLength()) {
815813
std::unique_ptr<BackingStore> old_out = std::move(*out);
816814
*out = ArrayBuffer::NewBackingStore(env()->isolate(), out_len);
817-
memcpy(static_cast<char*>((*out)->Data()),
818-
static_cast<char*>(old_out->Data()),
819-
out_len);
815+
memcpy((*out)->Data(), old_out->Data(), out_len);
820816
}
821817

822818
if (ok && kind_ == kCipher && IsAuthenticatedMode()) {
@@ -892,9 +888,7 @@ bool PublicKeyCipher::Cipher(
892888
*out = ArrayBuffer::NewBackingStore(env->isolate(), 0);
893889
} else {
894890
*out = ArrayBuffer::NewBackingStore(env->isolate(), buf.size());
895-
memcpy(static_cast<char*>((*out)->Data()),
896-
static_cast<char*>(buf.get()),
897-
buf.size());
891+
memcpy((*out)->Data(), buf.get(), buf.size());
898892
}
899893

900894
return true;

src/crypto/crypto_sig.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ std::unique_ptr<BackingStore> Node_SignFinal(Environment* env,
101101
if (sig_buf.len < sig->ByteLength()) {
102102
auto new_sig = ArrayBuffer::NewBackingStore(env->isolate(), sig_buf.len);
103103
if (sig_buf.len > 0) [[likely]] {
104-
memcpy(static_cast<char*>(new_sig->Data()),
105-
static_cast<char*>(sig->Data()),
106-
sig_buf.len);
104+
memcpy(new_sig->Data(), sig->Data(), sig_buf.len);
107105
}
108106
sig = std::move(new_sig);
109107
}

src/node_buffer.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,7 @@ MaybeLocal<Object> New(Isolate* isolate,
329329
if (actual < length) {
330330
std::unique_ptr<BackingStore> old_store = std::move(store);
331331
store = ArrayBuffer::NewBackingStore(isolate, actual);
332-
memcpy(static_cast<char*>(store->Data()),
333-
static_cast<char*>(old_store->Data()),
334-
actual);
332+
memcpy(store->Data(), old_store->Data(), actual);
335333
}
336334
Local<ArrayBuffer> buf = ArrayBuffer::New(isolate, std::move(store));
337335
Local<Object> obj;

src/node_http2.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,9 +2084,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
20842084
// Shrink to the actual amount of used data.
20852085
std::unique_ptr<BackingStore> old_bs = std::move(bs);
20862086
bs = ArrayBuffer::NewBackingStore(env()->isolate(), nread);
2087-
memcpy(static_cast<char*>(bs->Data()),
2088-
static_cast<char*>(old_bs->Data()),
2089-
nread);
2087+
memcpy(bs->Data(), old_bs->Data(), nread);
20902088
} else {
20912089
// This is a very unlikely case, and should only happen if the ReadStart()
20922090
// call in OnStreamAfterWrite() immediately provides data. If that does

src/stream_base.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
401401
// Copy partial data
402402
bs = ArrayBuffer::NewBackingStore(
403403
isolate, buf.len, BackingStoreInitializationMode::kUninitialized);
404-
memcpy(static_cast<char*>(bs->Data()), buf.base, buf.len);
404+
memcpy(bs->Data(), buf.base, buf.len);
405405
data_size = buf.len;
406406
} else {
407407
// Write it
@@ -709,9 +709,7 @@ void EmitToJSStreamListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
709709
if (static_cast<size_t>(nread) != bs->ByteLength()) {
710710
std::unique_ptr<BackingStore> old_bs = std::move(bs);
711711
bs = ArrayBuffer::NewBackingStore(isolate, nread);
712-
memcpy(static_cast<char*>(bs->Data()),
713-
static_cast<char*>(old_bs->Data()),
714-
nread);
712+
memcpy(bs->Data(), old_bs->Data(), nread);
715713
}
716714

717715
stream->CallJSOnreadMethod(nread, ArrayBuffer::New(isolate, std::move(bs)));

src/udp_wrap.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,7 @@ void UDPWrap::OnRecv(ssize_t nread,
760760
CHECK_LE(static_cast<size_t>(nread), bs->ByteLength());
761761
std::unique_ptr<BackingStore> old_bs = std::move(bs);
762762
bs = ArrayBuffer::NewBackingStore(isolate, nread);
763-
memcpy(static_cast<char*>(bs->Data()),
764-
static_cast<char*>(old_bs->Data()),
765-
nread);
763+
memcpy(bs->Data(), old_bs->Data(), nread);
766764
}
767765

768766
Local<Object> address;

0 commit comments

Comments
 (0)