Skip to content

Commit

Permalink
Add assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 27, 2025
1 parent c5235ba commit a624009
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
5 changes: 1 addition & 4 deletions cpp/s2p/s2p_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ using namespace spdlog;
string S2pServer::Init(int port)
{
assert(server_socket == -1);

if (port <= 0 || port > 65535) {
return fmt::format("Invalid port number: {}", port);
}
assert(port > 0 && port <= 65535);

server_socket = socket(PF_INET, SOCK_STREAM, 0);
if (server_socket == -1) {
Expand Down
3 changes: 0 additions & 3 deletions cpp/test/s2p_thread_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ TEST(S2pThreadTest, Init)
{
S2pThread service_thread;

EXPECT_FALSE(service_thread.Init(65536,nullptr, default_logger()).empty()) << "Illegal port number";
EXPECT_FALSE(service_thread.Init(0, nullptr, default_logger()).empty()) << "Illegal port number";
EXPECT_FALSE(service_thread.Init(-1, nullptr, default_logger()).empty()) << "Illegal port number";
EXPECT_TRUE(service_thread.Init(9999, nullptr,default_logger()).empty())
<< "Port 9999 is expected not to be in use for this test";
service_thread.Stop();
Expand Down

0 comments on commit a624009

Please sign in to comment.