Skip to content

Commit 5664dd2

Browse files
committed
src: use static_cast where appropriate
Use static_cast instead of reinterpret_cast when casting from void* to another type. This is mostly an aesthetic change but may help catch bugs when the affected code is modified.
1 parent 2b6c561 commit 5664dd2

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/cares_wrap.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class QueryWrap {
311311

312312
static void Callback(void *arg, int status, int timeouts,
313313
unsigned char* answer_buf, int answer_len) {
314-
QueryWrap* wrap = reinterpret_cast<QueryWrap*>(arg);
314+
QueryWrap* wrap = static_cast<QueryWrap*>(arg);
315315

316316
if (status != ARES_SUCCESS) {
317317
wrap->ParseError(status);
@@ -324,7 +324,7 @@ class QueryWrap {
324324

325325
static void Callback(void *arg, int status, int timeouts,
326326
struct hostent* host) {
327-
QueryWrap* wrap = reinterpret_cast<QueryWrap*>(arg);
327+
QueryWrap* wrap = static_cast<QueryWrap*>(arg);
328328

329329
if (status != ARES_SUCCESS) {
330330
wrap->ParseError(status);

src/fs_event_wrap.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class FSEventWrap: public HandleWrap {
5151

5252
FSEventWrap::FSEventWrap(Handle<Object> object): HandleWrap(object,
5353
(uv_handle_t*)&handle_) {
54-
handle_.data = reinterpret_cast<void*>(this);
54+
handle_.data = static_cast<void*>(this);
5555
initialized_ = false;
5656
}
5757

@@ -119,7 +119,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
119119
HandleScope scope;
120120
Local<String> eventStr;
121121

122-
FSEventWrap* wrap = reinterpret_cast<FSEventWrap*>(handle->data);
122+
FSEventWrap* wrap = static_cast<FSEventWrap*>(handle->data);
123123

124124
assert(wrap->object_.IsEmpty() == false);
125125

src/node_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class NODE_EXTERN Buffer: public ObjectWrap {
7575
static inline char* Data(v8::Handle<v8::Value> val) {
7676
assert(val->IsObject());
7777
void* data = val.As<v8::Object>()->GetIndexedPropertiesExternalArrayData();
78-
return reinterpret_cast<char*>(data);
78+
return static_cast<char*>(data);
7979
}
8080

8181
static inline char* Data(Buffer *b) {

src/pipe_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ PipeWrap::PipeWrap(Handle<Object> object, bool ipc)
129129
int r = uv_pipe_init(uv_default_loop(), &handle_, ipc);
130130
assert(r == 0); // How do we proxy this error up to javascript?
131131
// Suggestion: uv_pipe_init() returns void.
132-
handle_.data = reinterpret_cast<void*>(this);
132+
handle_.data = static_cast<void*>(this);
133133
UpdateWriteQueueSize();
134134
}
135135

src/v8_typed_array.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class TypedArray {
255255
}
256256

257257
void* buf = buffer->GetIndexedPropertiesExternalArrayData();
258-
char* begin = reinterpret_cast<char*>(buf) + byte_offset;
258+
char* begin = static_cast<char*>(buf) + byte_offset;
259259

260260
if (!checkAlignment(reinterpret_cast<uintptr_t>(begin), TBytes))
261261
return ThrowRangeError("Byte offset is not aligned.");
@@ -374,7 +374,7 @@ class TypedArray {
374374
// place as if all the data is first copied into a temporary buffer that
375375
// does not overlap either of the arrays, and then the data from the
376376
// temporary buffer is copied into the current array.
377-
memmove(reinterpret_cast<char*>(dst_ptr) + offset * TBytes, src_ptr,
377+
memmove(static_cast<char*>(dst_ptr) + offset * TBytes, src_ptr,
378378
src_length * TBytes);
379379
} else { // type[]
380380
if (args[1]->Int32Value() < 0)
@@ -643,7 +643,7 @@ class DataView {
643643

644644
// Like ArrayBuffer, we violate the spec and add an operator[].
645645
args.This()->SetIndexedPropertiesToExternalArrayData(
646-
reinterpret_cast<char*>(buf) + byte_offset,
646+
static_cast<char*>(buf) + byte_offset,
647647
v8::kExternalUnsignedByteArray, byte_length);
648648

649649
args.This()->Set(v8::String::New("buffer"),
@@ -670,7 +670,7 @@ class DataView {
670670
template <typename T>
671671
static T getValue(void* ptr, unsigned int index, bool swiz) {
672672
char buf[sizeof(T)];
673-
memcpy(buf, reinterpret_cast<char*>(ptr) + index, sizeof(T));
673+
memcpy(buf, static_cast<char*>(ptr) + index, sizeof(T));
674674
if (swiz)
675675
swizzle(buf, sizeof(T));
676676
T val;
@@ -684,7 +684,7 @@ class DataView {
684684
memcpy(buf, &val, sizeof(T));
685685
if (swiz)
686686
swizzle(buf, sizeof(T));
687-
memcpy(reinterpret_cast<char*>(ptr) + index, buf, sizeof(T));
687+
memcpy(static_cast<char*>(ptr) + index, buf, sizeof(T));
688688
}
689689

690690
template <typename T>

0 commit comments

Comments
 (0)