Skip to content

Commit 2b839a7

Browse files
committed
fix: static cast instead of reinterpret cast where possible
1 parent 30a5051 commit 2b839a7

File tree

10 files changed

+16
-20
lines changed

10 files changed

+16
-20
lines changed

src/context.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace zmq {
1111
Context::Context(const Napi::CallbackInfo& info)
12-
: Napi::ObjectWrap<Context>(info), module(*reinterpret_cast<Module*>(info.Data())) {
12+
: Napi::ObjectWrap<Context>(info), module(*static_cast<Module*>(info.Data())) {
1313
/* If this module has no global context, then create one with a process
1414
wide context pointer that is shared between threads/agents. */
1515
if (module.GlobalContext.IsEmpty()) {

src/incoming_msg.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Napi::Value IncomingMsg::IntoBuffer(const Napi::Env& env) {
2727
return env.Undefined();
2828
}
2929
}
30-
auto* data = reinterpret_cast<uint8_t*>(zmq_msg_data(ref->get()));
30+
auto* data = static_cast<uint8_t*>(zmq_msg_data(ref->get()));
3131
auto length = zmq_msg_size(ref->get());
3232

3333
if (noElectronMemoryCage) {

src/observer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ std::pair<const char*, const char*> ProtoError(uint32_t val) {
130130

131131
Observer::Observer(const Napi::CallbackInfo& info)
132132
: Napi::ObjectWrap<Observer>(info), async_context(Env(), "Observer"), poller(*this),
133-
module(*reinterpret_cast<Module*>(info.Data())) {
133+
module(*static_cast<Module*>(info.Data())) {
134134
Arg::Validator const args{
135135
Arg::Required<Arg::Object>("Socket must be a socket object"),
136136
};
@@ -263,7 +263,7 @@ void Observer::Receive(const Napi::Promise::Deferred& res) {
263263
}
264264
}
265265

266-
auto* data2 = reinterpret_cast<char*>(zmq_msg_data(&msg2));
266+
auto* data2 = static_cast<char*>(zmq_msg_data(&msg2));
267267
auto length = zmq_msg_size(&msg2);
268268

269269
auto event = Napi::Object::New(Env());

src/outgoing_msg.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ OutgoingMsg::OutgoingMsg(Napi::Value value, std::reference_wrapper<Module> modul
4848
auto length = str->size();
4949
auto* data = str->data();
5050

51-
auto release = [](void*, void* str) {
52-
delete reinterpret_cast<std::string*>(str);
53-
};
51+
auto release = [](void*, void* str) { delete static_cast<std::string*>(str); };
5452

5553
if (zmq_msg_init_data(&msg, data, length, release, str) < 0) {
5654
delete str;

src/poller.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Poller {
7575
readable_timer.get(),
7676
[](uv_timer_t* timer) {
7777
// NOLINTNEXTLINE(*-pro-type-reinterpret-cast)
78-
auto& poller = *reinterpret_cast<Poller*>(timer->data);
78+
auto& poller = *static_cast<Poller*>(timer->data);
7979
poller.Trigger(UV_READABLE);
8080
},
8181
static_cast<uint64_t>(timeout), 0);
@@ -100,7 +100,7 @@ class Poller {
100100
writable_timer.get(),
101101
[](uv_timer_t* timer) {
102102
// NOLINTNEXTLINE(*-pro-type-reinterpret-cast)
103-
auto& poller = *reinterpret_cast<Poller*>(timer->data);
103+
auto& poller = *static_cast<Poller*>(timer->data);
104104
poller.Trigger(UV_WRITABLE);
105105
},
106106
static_cast<uint64_t>(timeout), 0);
@@ -167,7 +167,7 @@ class Poller {
167167
static void Callback(uv_poll_t* poll, int32_t status, int32_t /*events*/) {
168168
if (status == 0) {
169169
// NOLINTNEXTLINE(*-pro-type-reinterpret-cast)
170-
auto& poller = *reinterpret_cast<Poller*>(poll->data);
170+
auto& poller = *static_cast<Poller*>(poll->data);
171171
poller.TriggerReadable();
172172
poller.TriggerWritable();
173173
}

src/proxy.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct ProxyContext {
2323

2424
Proxy::Proxy(const Napi::CallbackInfo& info)
2525
: Napi::ObjectWrap<Proxy>(info), async_context(Env(), "Proxy"),
26-
module(*reinterpret_cast<Module*>(info.Data())) {
26+
module(*static_cast<Module*>(info.Data())) {
2727
Arg::Validator const args{
2828
Arg::Required<Arg::Object>("Front-end must be a socket object"),
2929
Arg::Required<Arg::Object>("Back-end must be a socket object"),

src/socket.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct AddressContext {
6767

6868
Socket::Socket(const Napi::CallbackInfo& info)
6969
: Napi::ObjectWrap<Socket>(info), async_context(Env(), "Socket"), poller(*this),
70-
module(*reinterpret_cast<Module*>(info.Data())) {
70+
module(*static_cast<Module*>(info.Data())) {
7171
Arg::Validator const args{
7272
Arg::Required<Arg::Number>("Socket type must be a number"),
7373
Arg::Optional<Arg::Object>("Options must be an object"),
@@ -392,7 +392,7 @@ Napi::Value Socket::Bind(const Napi::CallbackInfo& info) {
392392
if (run_ctx->error != 0) {
393393
res.Reject(ErrnoException(
394394
Env(), static_cast<int32_t>(run_ctx->error), run_ctx->address)
395-
.Value());
395+
.Value());
396396
return;
397397
}
398398

@@ -448,7 +448,7 @@ Napi::Value Socket::Unbind(const Napi::CallbackInfo& info) {
448448
if (run_ctx->error != 0) {
449449
res.Reject(ErrnoException(
450450
Env(), static_cast<int32_t>(run_ctx->error), run_ctx->address)
451-
.Value());
451+
.Value());
452452
return;
453453
}
454454

src/util/trash.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ class Trash {
2525

2626
async->data = this;
2727

28-
auto clear = [](uv_async_t* async) {
29-
reinterpret_cast<Trash*>(async->data)->Clear();
30-
};
28+
auto clear = [](uv_async_t* async) { static_cast<Trash*>(async->data)->Clear(); };
3129

3230
[[maybe_unused]] auto err = uv_async_init(loop, async.get(), clear);
3331
assert(err == 0);

src/util/uvdelayed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class UvDelayed {
3333
assert(err == 0);
3434

3535
err = uv_check_start(check.get(), [](uv_check_t* check) {
36-
auto& immediate = *reinterpret_cast<UvDelayed*>(check->data);
36+
auto& immediate = *static_cast<UvDelayed*>(check->data);
3737
immediate.check.reset();
3838
immediate.idle.reset();
3939
immediate.delayed_callback();

src/util/uvwork.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ class UvWork {
2323
auto err = uv_queue_work(
2424
loop, work.get(),
2525
[](uv_work_t* req) {
26-
auto& work = *reinterpret_cast<UvWork*>(req->data);
26+
auto& work = *static_cast<UvWork*>(req->data);
2727
work.execute_callback();
2828
},
2929
[](uv_work_t* req, int /*status*/) {
30-
auto& work = *reinterpret_cast<UvWork*>(req->data);
30+
auto& work = *static_cast<UvWork*>(req->data);
3131
work.complete_callback();
3232
delete &work;
3333
});

0 commit comments

Comments
 (0)