From 5664dd2fc1e872a850c2891ee11f86e98b69106d Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 5 Jan 2013 00:11:37 +0100 Subject: [PATCH] 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. --- src/cares_wrap.cc | 4 ++-- src/fs_event_wrap.cc | 4 ++-- src/node_buffer.h | 2 +- src/pipe_wrap.cc | 2 +- src/v8_typed_array.cc | 10 +++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 4d01ee4026..60378a5103 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -311,7 +311,7 @@ class QueryWrap { static void Callback(void *arg, int status, int timeouts, unsigned char* answer_buf, int answer_len) { - QueryWrap* wrap = reinterpret_cast(arg); + QueryWrap* wrap = static_cast(arg); if (status != ARES_SUCCESS) { wrap->ParseError(status); @@ -324,7 +324,7 @@ class QueryWrap { static void Callback(void *arg, int status, int timeouts, struct hostent* host) { - QueryWrap* wrap = reinterpret_cast(arg); + QueryWrap* wrap = static_cast(arg); if (status != ARES_SUCCESS) { wrap->ParseError(status); diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 0153b31026..15ad2f71bc 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -51,7 +51,7 @@ private: FSEventWrap::FSEventWrap(Handle object): HandleWrap(object, (uv_handle_t*)&handle_) { - handle_.data = reinterpret_cast(this); + handle_.data = static_cast(this); initialized_ = false; } @@ -119,7 +119,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename, HandleScope scope; Local eventStr; - FSEventWrap* wrap = reinterpret_cast(handle->data); + FSEventWrap* wrap = static_cast(handle->data); assert(wrap->object_.IsEmpty() == false); diff --git a/src/node_buffer.h b/src/node_buffer.h index 137a6cfb40..f3d9dd4681 100644 --- a/src/node_buffer.h +++ b/src/node_buffer.h @@ -75,7 +75,7 @@ class NODE_EXTERN Buffer: public ObjectWrap { static inline char* Data(v8::Handle val) { assert(val->IsObject()); void* data = val.As()->GetIndexedPropertiesExternalArrayData(); - return reinterpret_cast(data); + return static_cast(data); } static inline char* Data(Buffer *b) { diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 0c60b4af4e..eb00e18aa1 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -129,7 +129,7 @@ PipeWrap::PipeWrap(Handle object, bool ipc) int r = uv_pipe_init(uv_default_loop(), &handle_, ipc); assert(r == 0); // How do we proxy this error up to javascript? // Suggestion: uv_pipe_init() returns void. - handle_.data = reinterpret_cast(this); + handle_.data = static_cast(this); UpdateWriteQueueSize(); } diff --git a/src/v8_typed_array.cc b/src/v8_typed_array.cc index f7811309ad..2650537e6f 100644 --- a/src/v8_typed_array.cc +++ b/src/v8_typed_array.cc @@ -255,7 +255,7 @@ class TypedArray { } void* buf = buffer->GetIndexedPropertiesExternalArrayData(); - char* begin = reinterpret_cast(buf) + byte_offset; + char* begin = static_cast(buf) + byte_offset; if (!checkAlignment(reinterpret_cast(begin), TBytes)) return ThrowRangeError("Byte offset is not aligned."); @@ -374,7 +374,7 @@ class TypedArray { // place as if all the data is first copied into a temporary buffer that // does not overlap either of the arrays, and then the data from the // temporary buffer is copied into the current array. - memmove(reinterpret_cast(dst_ptr) + offset * TBytes, src_ptr, + memmove(static_cast(dst_ptr) + offset * TBytes, src_ptr, src_length * TBytes); } else { // type[] if (args[1]->Int32Value() < 0) @@ -643,7 +643,7 @@ class DataView { // Like ArrayBuffer, we violate the spec and add an operator[]. args.This()->SetIndexedPropertiesToExternalArrayData( - reinterpret_cast(buf) + byte_offset, + static_cast(buf) + byte_offset, v8::kExternalUnsignedByteArray, byte_length); args.This()->Set(v8::String::New("buffer"), @@ -670,7 +670,7 @@ class DataView { template static T getValue(void* ptr, unsigned int index, bool swiz) { char buf[sizeof(T)]; - memcpy(buf, reinterpret_cast(ptr) + index, sizeof(T)); + memcpy(buf, static_cast(ptr) + index, sizeof(T)); if (swiz) swizzle(buf, sizeof(T)); T val; @@ -684,7 +684,7 @@ class DataView { memcpy(buf, &val, sizeof(T)); if (swiz) swizzle(buf, sizeof(T)); - memcpy(reinterpret_cast(ptr) + index, buf, sizeof(T)); + memcpy(static_cast(ptr) + index, buf, sizeof(T)); } template