Skip to content

Commit 648ad25

Browse files
tniessenaduh95
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 680b434 commit 648ad25

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
@@ -793,9 +793,7 @@ CipherBase::UpdateResult CipherBase::Update(
793793
} else if (static_cast<size_t>(buf_len) != (*out)->ByteLength()) {
794794
std::unique_ptr<BackingStore> old_out = std::move(*out);
795795
*out = ArrayBuffer::NewBackingStore(env()->isolate(), buf_len);
796-
memcpy(static_cast<char*>((*out)->Data()),
797-
static_cast<char*>(old_out->Data()),
798-
buf_len);
796+
memcpy((*out)->Data(), old_out->Data(), buf_len);
799797
}
800798

801799
// When in CCM mode, EVP_CipherUpdate will fail if the authentication tag is
@@ -890,9 +888,7 @@ bool CipherBase::Final(std::unique_ptr<BackingStore>* out) {
890888
} else if (static_cast<size_t>(out_len) != (*out)->ByteLength()) {
891889
std::unique_ptr<BackingStore> old_out = std::move(*out);
892890
*out = ArrayBuffer::NewBackingStore(env()->isolate(), out_len);
893-
memcpy(static_cast<char*>((*out)->Data()),
894-
static_cast<char*>(old_out->Data()),
895-
out_len);
891+
memcpy((*out)->Data(), old_out->Data(), out_len);
896892
}
897893

898894
if (ok && kind_ == kCipher && IsAuthenticatedMode()) {
@@ -996,9 +992,7 @@ bool PublicKeyCipher::Cipher(
996992
} else if (out_len != (*out)->ByteLength()) {
997993
std::unique_ptr<BackingStore> old_out = std::move(*out);
998994
*out = ArrayBuffer::NewBackingStore(env->isolate(), out_len);
999-
memcpy(static_cast<char*>((*out)->Data()),
1000-
static_cast<char*>(old_out->Data()),
1001-
out_len);
995+
memcpy((*out)->Data(), old_out->Data(), out_len);
1002996
}
1003997

1004998
return true;

src/crypto/crypto_sig.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ std::unique_ptr<BackingStore> Node_SignFinal(Environment* env,
113113
} else if (sig_len != sig->ByteLength()) {
114114
std::unique_ptr<BackingStore> old_sig = std::move(sig);
115115
sig = ArrayBuffer::NewBackingStore(env->isolate(), sig_len);
116-
memcpy(static_cast<char*>(sig->Data()),
117-
static_cast<char*>(old_sig->Data()),
118-
sig_len);
116+
memcpy(sig->Data(), old_sig->Data(), sig_len);
119117
}
120118
return sig;
121119
}

src/node_buffer.cc

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

src/node_http2.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,9 +2107,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
21072107
// Shrink to the actual amount of used data.
21082108
std::unique_ptr<BackingStore> old_bs = std::move(bs);
21092109
bs = ArrayBuffer::NewBackingStore(env()->isolate(), nread);
2110-
memcpy(static_cast<char*>(bs->Data()),
2111-
static_cast<char*>(old_bs->Data()),
2112-
nread);
2110+
memcpy(bs->Data(), old_bs->Data(), nread);
21132111
} else {
21142112
// This is a very unlikely case, and should only happen if the ReadStart()
21152113
// 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
@@ -400,7 +400,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
400400
// Copy partial data
401401
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
402402
bs = ArrayBuffer::NewBackingStore(isolate, buf.len);
403-
memcpy(static_cast<char*>(bs->Data()), buf.base, buf.len);
403+
memcpy(bs->Data(), buf.base, buf.len);
404404
data_size = buf.len;
405405
} else {
406406
// Write it
@@ -708,9 +708,7 @@ void EmitToJSStreamListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
708708
if (static_cast<size_t>(nread) != bs->ByteLength()) {
709709
std::unique_ptr<BackingStore> old_bs = std::move(bs);
710710
bs = ArrayBuffer::NewBackingStore(isolate, nread);
711-
memcpy(static_cast<char*>(bs->Data()),
712-
static_cast<char*>(old_bs->Data()),
713-
nread);
711+
memcpy(bs->Data(), old_bs->Data(), nread);
714712
}
715713

716714
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)