src: remove `void*` -> `char*` -> `void*` casts · nodejs/node@648ad25 · GitHub
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 <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 680b434 commit 648ad25

6 files changed

Lines changed: 9 additions & 25 deletions

File tree

src/crypto/crypto_cipher.cc

Lines changed: 3 additions & 9 deletions

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

0 commit comments

Comments
 (0)