Skip to content

Commit 0371c68

Browse files
committed
More defensive/sensible handling of a case that probably can't happen.
I found this by running clang-analyzer. With the previous version of the code, if `handler` is null, then we assign `self = nullptr` and then immediately call a method on it. I'm pretty sure this can't actually happen -- I don't think `uv_timer_start` will ever pass nullptr to the callback -- but the logic is obviously bogus so let's replace it with something defensive.
1 parent ae6f591 commit 0371c68

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/node-capnp/capnp.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ class UvEventPort: public kj::EventPort {
194194
}
195195

196196
static void doRun(uv_timer_t* handle) {
197-
UvEventPort* self = handle == nullptr ? nullptr : reinterpret_cast<UvEventPort*>(handle->data);
197+
KJ_ASSERT(handle != nullptr);
198+
UvEventPort* self = reinterpret_cast<UvEventPort*>(handle->data);
198199
self->run();
199200
}
200201
};

0 commit comments

Comments
 (0)