Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
src: use static_cast where appropriate
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bnoordhuis committed Jan 4, 2013
1 parent 2b6c561 commit 5664dd2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<QueryWrap*>(arg);
QueryWrap* wrap = static_cast<QueryWrap*>(arg);

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

static void Callback(void *arg, int status, int timeouts,
struct hostent* host) {
QueryWrap* wrap = reinterpret_cast<QueryWrap*>(arg);
QueryWrap* wrap = static_cast<QueryWrap*>(arg);

if (status != ARES_SUCCESS) {
wrap->ParseError(status);
Expand Down
4 changes: 2 additions & 2 deletions src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class FSEventWrap: public HandleWrap {

FSEventWrap::FSEventWrap(Handle<Object> object): HandleWrap(object,
(uv_handle_t*)&handle_) {
handle_.data = reinterpret_cast<void*>(this);
handle_.data = static_cast<void*>(this);
initialized_ = false;
}

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/node_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class NODE_EXTERN Buffer: public ObjectWrap {
static inline char* Data(v8::Handle<v8::Value> val) {
assert(val->IsObject());
void* data = val.As<v8::Object>()->GetIndexedPropertiesExternalArrayData();
return reinterpret_cast<char*>(data);
return static_cast<char*>(data);
}

static inline char* Data(Buffer *b) {
Expand Down
2 changes: 1 addition & 1 deletion src/pipe_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ PipeWrap::PipeWrap(Handle<Object> 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<void*>(this);
handle_.data = static_cast<void*>(this);
UpdateWriteQueueSize();
}

Expand Down
10 changes: 5 additions & 5 deletions src/v8_typed_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class TypedArray {
}

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

if (!checkAlignment(reinterpret_cast<uintptr_t>(begin), TBytes))
return ThrowRangeError("Byte offset is not aligned.");
Expand Down Expand Up @@ -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<char*>(dst_ptr) + offset * TBytes, src_ptr,
memmove(static_cast<char*>(dst_ptr) + offset * TBytes, src_ptr,
src_length * TBytes);
} else { // type[]
if (args[1]->Int32Value() < 0)
Expand Down Expand Up @@ -643,7 +643,7 @@ class DataView {

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

args.This()->Set(v8::String::New("buffer"),
Expand All @@ -670,7 +670,7 @@ class DataView {
template <typename T>
static T getValue(void* ptr, unsigned int index, bool swiz) {
char buf[sizeof(T)];
memcpy(buf, reinterpret_cast<char*>(ptr) + index, sizeof(T));
memcpy(buf, static_cast<char*>(ptr) + index, sizeof(T));
if (swiz)
swizzle(buf, sizeof(T));
T val;
Expand All @@ -684,7 +684,7 @@ class DataView {
memcpy(buf, &val, sizeof(T));
if (swiz)
swizzle(buf, sizeof(T));
memcpy(reinterpret_cast<char*>(ptr) + index, buf, sizeof(T));
memcpy(static_cast<char*>(ptr) + index, buf, sizeof(T));
}

template <typename T>
Expand Down

0 comments on commit 5664dd2

Please sign in to comment.