Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: zmq_ctx_get API broken #4038

Merged
merged 1 commit into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/zmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,11 @@ int zmq_ctx_set_ext (void *ctx_,

int zmq_ctx_get (void *ctx_, int option_)
{
int optval = 0;
size_t optvallen = sizeof (int);
if (zmq_ctx_get_ext (ctx_, option_, &optval, &optvallen) == 0) {
return optval;
if (!ctx_ || !(static_cast<zmq::ctx_t *> (ctx_))->check_tag ()) {
errno = EFAULT;
return -1;
}

errno = EFAULT;
return -1;
return (static_cast<zmq::ctx_t *> (ctx_))->get (option_);
}

int zmq_ctx_get_ext (void *ctx_, int option_, void *optval_, size_t *optvallen_)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_ctx_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ void test_ctx_option_blocky ()
test_context_socket_close (router);
}

void test_ctx_option_invalid ()
{
TEST_ASSERT_EQUAL_INT (-1, zmq_ctx_set (get_test_context (), -1, 0));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for the future: You can simply write:

     TEST_ASSERT_FAILURE_ERRNO (EINVAL, zmq_ctx_set (get_test_context (), -1, 0));

instead of the two separate assertions.

TEST_ASSERT_EQUAL_INT (EINVAL, errno);
TEST_ASSERT_EQUAL_INT (-1, zmq_ctx_get (get_test_context (), -1));
TEST_ASSERT_EQUAL_INT (EINVAL, errno);
}

int main (void)
{
setup_test_environment ();
Expand All @@ -297,5 +305,6 @@ int main (void)
RUN_TEST (test_ctx_thread_opts);
RUN_TEST (test_ctx_zero_copy);
RUN_TEST (test_ctx_option_blocky);
RUN_TEST (test_ctx_option_invalid);
return UNITY_END ();
}