Skip to content

Commit f282307

Browse files
committed
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: nodejs#52292
1 parent b6a10f7 commit f282307

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
@@ -781,9 +781,7 @@ CipherBase::UpdateResult CipherBase::Update(
781781
} else if (static_cast<size_t>(buf_len) != (*out)->ByteLength()) {
782782
std::unique_ptr<BackingStore> old_out = std::move(*out);
783783
*out = ArrayBuffer::NewBackingStore(env()->isolate(), buf_len);
784-
memcpy(static_cast<char*>((*out)->Data()),
785-
static_cast<char*>(old_out->Data()),
786-
buf_len);
784+
memcpy((*out)->Data(), old_out->Data(), buf_len);
787785
}
788786

789787
// When in CCM mode, EVP_CipherUpdate will fail if the authentication tag is
@@ -879,9 +877,7 @@ bool CipherBase::Final(std::unique_ptr<BackingStore>* out) {
879877
} else if (static_cast<size_t>(out_len) != (*out)->ByteLength()) {
880878
std::unique_ptr<BackingStore> old_out = std::move(*out);
881879
*out = ArrayBuffer::NewBackingStore(env()->isolate(), out_len);
882-
memcpy(static_cast<char*>((*out)->Data()),
883-
static_cast<char*>(old_out->Data()),
884-
out_len);
880+
memcpy((*out)->Data(), old_out->Data(), out_len);
885881
}
886882

887883
if (ok && kind_ == kCipher && IsAuthenticatedMode()) {
@@ -957,9 +953,7 @@ bool PublicKeyCipher::Cipher(
957953
*out = ArrayBuffer::NewBackingStore(env->isolate(), 0);
958954
} else {
959955
*out = ArrayBuffer::NewBackingStore(env->isolate(), buf.size());
960-
memcpy(static_cast<char*>((*out)->Data()),
961-
static_cast<char*>(buf.get()),
962-
buf.size());
956+
memcpy((*out)->Data(), buf.get(), buf.size());
963957
}
964958

965959
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
@@ -2079,9 +2079,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
20792079
// Shrink to the actual amount of used data.
20802080
std::unique_ptr<BackingStore> old_bs = std::move(bs);
20812081
bs = ArrayBuffer::NewBackingStore(env()->isolate(), nread);
2082-
memcpy(static_cast<char*>(bs->Data()),
2083-
static_cast<char*>(old_bs->Data()),
2084-
nread);
2082+
memcpy(bs->Data(), old_bs->Data(), nread);
20852083
} else {
20862084
// This is a very unlikely case, and should only happen if the ReadStart()
20872085
// 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)