mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
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.
This commit is contained in:
1 parent
2b6c561040
commit
5664dd2fc1
5 files changed
+11
-11
No files matched your search
+2
-2
@@ -311,7 +311,7 @@ class QueryWrap {
|
|||||||
|
|
||||||
static void Callback(void *arg, int status, int timeouts,
|
static void Callback(void *arg, int status, int timeouts,
|
||||||
unsigned char* answer_buf, int answer_len) {
|
unsigned char* answer_buf, int answer_len) {
|
||||||
QueryWrap* wrap = reinterpret_cast<QueryWrap*>(arg);
|
QueryWrap* wrap = static_cast<QueryWrap*>(arg);
|
||||||
|
|
||||||
if (status != ARES_SUCCESS) {
|
if (status != ARES_SUCCESS) {
|
||||||
wrap->ParseError(status);
|
wrap->ParseError(status);
|
||||||
@@ -324,7 +324,7 @@ class QueryWrap {
|
|||||||
|
|
||||||
static void Callback(void *arg, int status, int timeouts,
|
static void Callback(void *arg, int status, int timeouts,
|
||||||
struct hostent* host) {
|
struct hostent* host) {
|
||||||
QueryWrap* wrap = reinterpret_cast<QueryWrap*>(arg);
|
QueryWrap* wrap = static_cast<QueryWrap*>(arg);
|
||||||
|
|
||||||
if (status != ARES_SUCCESS) {
|
if (status != ARES_SUCCESS) {
|
||||||
wrap->ParseError(status);
|
wrap->ParseError(status);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ private:
|
|||||||
|
|
||||||
FSEventWrap::FSEventWrap(Handle<Object> object): HandleWrap(object,
|
FSEventWrap::FSEventWrap(Handle<Object> object): HandleWrap(object,
|
||||||
(uv_handle_t*)&handle_) {
|
(uv_handle_t*)&handle_) {
|
||||||
handle_.data = reinterpret_cast<void*>(this);
|
handle_.data = static_cast<void*>(this);
|
||||||
initialized_ = false;
|
initialized_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
|
|||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
Local<String> eventStr;
|
Local<String> eventStr;
|
||||||
|
|
||||||
FSEventWrap* wrap = reinterpret_cast<FSEventWrap*>(handle->data);
|
FSEventWrap* wrap = static_cast<FSEventWrap*>(handle->data);
|
||||||
|
|
||||||
assert(wrap->object_.IsEmpty() == false);
|
assert(wrap->object_.IsEmpty() == false);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -75,7 +75,7 @@ class NODE_EXTERN Buffer: public ObjectWrap {
|
|||||||
static inline char* Data(v8::Handle<v8::Value> val) {
|
static inline char* Data(v8::Handle<v8::Value> val) {
|
||||||
assert(val->IsObject());
|
assert(val->IsObject());
|
||||||
void* data = val.As<v8::Object>()->GetIndexedPropertiesExternalArrayData();
|
void* data = val.As<v8::Object>()->GetIndexedPropertiesExternalArrayData();
|
||||||
return reinterpret_cast<char*>(data);
|
return static_cast<char*>(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char* Data(Buffer *b) {
|
static inline char* Data(Buffer *b) {
|
||||||
|
|||||||
+1
-1
@@ -129,7 +129,7 @@ PipeWrap::PipeWrap(Handle<Object> object, bool ipc)
|
|||||||
int r = uv_pipe_init(uv_default_loop(), &handle_, ipc);
|
int r = uv_pipe_init(uv_default_loop(), &handle_, ipc);
|
||||||
assert(r == 0); // How do we proxy this error up to javascript?
|
assert(r == 0); // How do we proxy this error up to javascript?
|
||||||
// Suggestion: uv_pipe_init() returns void.
|
// Suggestion: uv_pipe_init() returns void.
|
||||||
handle_.data = reinterpret_cast<void*>(this);
|
handle_.data = static_cast<void*>(this);
|
||||||
UpdateWriteQueueSize();
|
UpdateWriteQueueSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ class TypedArray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void* buf = buffer->GetIndexedPropertiesExternalArrayData();
|
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))
|
if (!checkAlignment(reinterpret_cast<uintptr_t>(begin), TBytes))
|
||||||
return ThrowRangeError("Byte offset is not aligned.");
|
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
|
// 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
|
// does not overlap either of the arrays, and then the data from the
|
||||||
// temporary buffer is copied into the current array.
|
// 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);
|
src_length * TBytes);
|
||||||
} else { // type[]
|
} else { // type[]
|
||||||
if (args[1]->Int32Value() < 0)
|
if (args[1]->Int32Value() < 0)
|
||||||
@@ -643,7 +643,7 @@ class DataView {
|
|||||||
|
|
||||||
// Like ArrayBuffer, we violate the spec and add an operator[].
|
// Like ArrayBuffer, we violate the spec and add an operator[].
|
||||||
args.This()->SetIndexedPropertiesToExternalArrayData(
|
args.This()->SetIndexedPropertiesToExternalArrayData(
|
||||||
reinterpret_cast<char*>(buf) + byte_offset,
|
static_cast<char*>(buf) + byte_offset,
|
||||||
v8::kExternalUnsignedByteArray, byte_length);
|
v8::kExternalUnsignedByteArray, byte_length);
|
||||||
|
|
||||||
args.This()->Set(v8::String::New("buffer"),
|
args.This()->Set(v8::String::New("buffer"),
|
||||||
@@ -670,7 +670,7 @@ class DataView {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
static T getValue(void* ptr, unsigned int index, bool swiz) {
|
static T getValue(void* ptr, unsigned int index, bool swiz) {
|
||||||
char buf[sizeof(T)];
|
char buf[sizeof(T)];
|
||||||
memcpy(buf, reinterpret_cast<char*>(ptr) + index, sizeof(T));
|
memcpy(buf, static_cast<char*>(ptr) + index, sizeof(T));
|
||||||
if (swiz)
|
if (swiz)
|
||||||
swizzle(buf, sizeof(T));
|
swizzle(buf, sizeof(T));
|
||||||
T val;
|
T val;
|
||||||
@@ -684,7 +684,7 @@ class DataView {
|
|||||||
memcpy(buf, &val, sizeof(T));
|
memcpy(buf, &val, sizeof(T));
|
||||||
if (swiz)
|
if (swiz)
|
||||||
swizzle(buf, sizeof(T));
|
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>
|
template <typename T>
|
||||||
|
|||||||
Reference in new issue
Block a user