Skip to content

Commit

Permalink
src: use UNREACHABLE instead of CHECK(falsy)
Browse files Browse the repository at this point in the history
Also remove some dead code following such statements.

PR-URL: #46317
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
  • Loading branch information
tniessen authored and juanarbol committed Mar 3, 2023
1 parent fa43929 commit d3621c8
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 21 deletions.
7 changes: 3 additions & 4 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ int ParseGeneralReply(
status = ares_parse_ptr_reply(buf, len, nullptr, 0, AF_INET, &host);
break;
default:
CHECK(0 && "Bad NS type");
break;
UNREACHABLE("Bad NS type");
}

if (status != ARES_SUCCESS)
Expand Down Expand Up @@ -1578,7 +1577,7 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
family = AF_INET6;
break;
default:
CHECK(0 && "bad address family");
UNREACHABLE("bad address family");
}

auto req_wrap = std::make_unique<GetAddrInfoReqWrap>(env,
Expand Down Expand Up @@ -1736,7 +1735,7 @@ void SetServers(const FunctionCallbackInfo<Value>& args) {
err = uv_inet_pton(AF_INET6, *ip, &cur->addr);
break;
default:
CHECK(0 && "Bad address family.");
UNREACHABLE("Bad address family");
}

if (err)
Expand Down
7 changes: 2 additions & 5 deletions src/crypto/crypto_bio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,9 @@ long NodeBIO::Ctrl(BIO* bio, int cmd, long num, // NOLINT(runtime/int)
*reinterpret_cast<void**>(ptr) = nullptr;
break;
case BIO_C_SET_BUF_MEM:
CHECK(0 && "Can't use SET_BUF_MEM_PTR with NodeBIO");
break;
UNREACHABLE("Can't use SET_BUF_MEM_PTR with NodeBIO");
case BIO_C_GET_BUF_MEM_PTR:
CHECK(0 && "Can't use GET_BUF_MEM_PTR with NodeBIO");
ret = 0;
break;
UNREACHABLE("Can't use GET_BUF_MEM_PTR with NodeBIO");
case BIO_CTRL_GET_CLOSE:
ret = BIO_get_shutdown(bio);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ BaseObjectPtr<BaseObject> NativeKeyObject::KeyObjectTransferData::Deserialize(
key_ctor = env->crypto_key_object_private_constructor();
break;
default:
CHECK(false);
UNREACHABLE();
}

Local<Value> key;
Expand Down
2 changes: 1 addition & 1 deletion src/debug_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ void CheckedUvLoopClose(uv_loop_t* loop) {

fflush(stderr);
// Finally, abort.
CHECK(0 && "uv_loop_close() while having open handles");
UNREACHABLE("uv_loop_close() while having open handles");
}

void PrintLibuvHandleInformation(uv_loop_t* loop, FILE* stream) {
Expand Down
2 changes: 1 addition & 1 deletion src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
} else if (events & UV_CHANGE) {
event_string = env->change_string();
} else {
CHECK(0 && "bad fs events flag");
UNREACHABLE("bad fs events flag");
}

Local<Value> argv[] = {
Expand Down
4 changes: 2 additions & 2 deletions src/node_zlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
flush != Z_FULL_FLUSH &&
flush != Z_FINISH &&
flush != Z_BLOCK) {
CHECK(0 && "Invalid flush value");
UNREACHABLE("Invalid flush value");
}

if (args[1]->IsNull()) {
Expand Down Expand Up @@ -814,7 +814,7 @@ void ZlibContext::DoThreadPoolWork() {

break;
default:
CHECK(0 && "invalid number of gzip magic number bytes read");
UNREACHABLE("invalid number of gzip magic number bytes read");
}

[[fallthrough]];
Expand Down
3 changes: 1 addition & 2 deletions src/spawn_sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,7 @@ int SyncProcessRunner::ParseStdioOption(int child_fd,
return AddStdioInheritFD(child_fd, inherit_fd);

} else {
CHECK(0 && "invalid child stdio type");
return UV_EINVAL;
UNREACHABLE("invalid child stdio type");
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ size_t StringBytes::Write(Isolate* isolate,
break;

default:
CHECK(0 && "unknown encoding");
break;
UNREACHABLE("unknown encoding");
}

return nbytes;
Expand Down Expand Up @@ -423,8 +422,7 @@ Maybe<size_t> StringBytes::StorageSize(Isolate* isolate,
break;

default:
CHECK(0 && "unknown encoding");
break;
UNREACHABLE("unknown encoding");
}

return Just(data_size);
Expand Down
2 changes: 1 addition & 1 deletion src/udp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ int sockaddr_for_family(int address_family,
case AF_INET6:
return uv_ip6_addr(address, port, reinterpret_cast<sockaddr_in6*>(addr));
default:
CHECK(0 && "unexpected address family");
UNREACHABLE("unexpected address family");
}
}

Expand Down

0 comments on commit d3621c8

Please sign in to comment.