Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
  • Loading branch information
tniessen committed Apr 8, 2025
commit f282307594fc82b5dfd965f760ff693d1ca558dc
12 changes: 3 additions & 9 deletions src/crypto/crypto_cipher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -781,9 +781,7 @@ CipherBase::UpdateResult CipherBase::Update(
} else if (static_cast<size_t>(buf_len) != (*out)->ByteLength()) {
std::unique_ptr<BackingStore> old_out = std::move(*out);
*out = ArrayBuffer::NewBackingStore(env()->isolate(), buf_len);
memcpy(static_cast<char*>((*out)->Data()),
static_cast<char*>(old_out->Data()),
buf_len);
memcpy((*out)->Data(), old_out->Data(), buf_len);
}

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

if (ok && kind_ == kCipher && IsAuthenticatedMode()) {
Expand Down Expand Up @@ -957,9 +953,7 @@ bool PublicKeyCipher::Cipher(
*out = ArrayBuffer::NewBackingStore(env->isolate(), 0);
} else {
*out = ArrayBuffer::NewBackingStore(env->isolate(), buf.size());
memcpy(static_cast<char*>((*out)->Data()),
static_cast<char*>(buf.get()),
buf.size());
memcpy((*out)->Data(), buf.get(), buf.size());
}

return true;
Expand Down
4 changes: 1 addition & 3 deletions src/crypto/crypto_sig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ std::unique_ptr<BackingStore> Node_SignFinal(Environment* env,
if (sig_buf.len < sig->ByteLength()) {
auto new_sig = ArrayBuffer::NewBackingStore(env->isolate(), sig_buf.len);
if (sig_buf.len > 0) [[likely]] {
memcpy(static_cast<char*>(new_sig->Data()),
static_cast<char*>(sig->Data()),
sig_buf.len);
memcpy(new_sig->Data(), sig->Data(), sig_buf.len);
}
sig = std::move(new_sig);
}
Expand Down
4 changes: 1 addition & 3 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,7 @@ MaybeLocal<Object> New(Isolate* isolate,
if (actual < length) {
std::unique_ptr<BackingStore> old_store = std::move(store);
store = ArrayBuffer::NewBackingStore(isolate, actual);
memcpy(static_cast<char*>(store->Data()),
static_cast<char*>(old_store->Data()),
actual);
memcpy(store->Data(), old_store->Data(), actual);
}
Local<ArrayBuffer> buf = ArrayBuffer::New(isolate, std::move(store));
Local<Object> obj;
Expand Down
4 changes: 1 addition & 3 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2079,9 +2079,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
// Shrink to the actual amount of used data.
std::unique_ptr<BackingStore> old_bs = std::move(bs);
bs = ArrayBuffer::NewBackingStore(env()->isolate(), nread);
memcpy(static_cast<char*>(bs->Data()),
static_cast<char*>(old_bs->Data()),
nread);
memcpy(bs->Data(), old_bs->Data(), nread);
} else {
// This is a very unlikely case, and should only happen if the ReadStart()
// call in OnStreamAfterWrite() immediately provides data. If that does
Expand Down
6 changes: 2 additions & 4 deletions src/stream_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
// Copy partial data
bs = ArrayBuffer::NewBackingStore(
isolate, buf.len, BackingStoreInitializationMode::kUninitialized);
memcpy(static_cast<char*>(bs->Data()), buf.base, buf.len);
memcpy(bs->Data(), buf.base, buf.len);
data_size = buf.len;
} else {
// Write it
Expand Down Expand Up @@ -709,9 +709,7 @@ void EmitToJSStreamListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
if (static_cast<size_t>(nread) != bs->ByteLength()) {
std::unique_ptr<BackingStore> old_bs = std::move(bs);
bs = ArrayBuffer::NewBackingStore(isolate, nread);
memcpy(static_cast<char*>(bs->Data()),
static_cast<char*>(old_bs->Data()),
nread);
memcpy(bs->Data(), old_bs->Data(), nread);
}

stream->CallJSOnreadMethod(nread, ArrayBuffer::New(isolate, std::move(bs)));
Expand Down
4 changes: 1 addition & 3 deletions src/udp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,7 @@ void UDPWrap::OnRecv(ssize_t nread,
CHECK_LE(static_cast<size_t>(nread), bs->ByteLength());
std::unique_ptr<BackingStore> old_bs = std::move(bs);
bs = ArrayBuffer::NewBackingStore(isolate, nread);
memcpy(static_cast<char*>(bs->Data()),
static_cast<char*>(old_bs->Data()),
nread);
memcpy(bs->Data(), old_bs->Data(), nread);
}

Local<Object> address;
Expand Down
Loading