0
0
mirror of https://github.com/zeromq/libzmq.git synced 2025-01-14 09:47:56 +08:00

Merge pull request #4038 from bluca/api_breakage

Problem: zmq_ctx_get API broken
This commit is contained in:
Doron Somech 2020-09-11 09:54:50 +03:00 committed by GitHub
commit e915449184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -195,14 +195,11 @@ int zmq_ctx_set_ext (void *ctx_,
int zmq_ctx_get (void *ctx_, int option_) int zmq_ctx_get (void *ctx_, int option_)
{ {
int optval = 0; if (!ctx_ || !(static_cast<zmq::ctx_t *> (ctx_))->check_tag ()) {
size_t optvallen = sizeof (int); errno = EFAULT;
if (zmq_ctx_get_ext (ctx_, option_, &optval, &optvallen) == 0) { return -1;
return optval;
} }
return (static_cast<zmq::ctx_t *> (ctx_))->get (option_);
errno = EFAULT;
return -1;
} }
int zmq_ctx_get_ext (void *ctx_, int option_, void *optval_, size_t *optvallen_) int zmq_ctx_get_ext (void *ctx_, int option_, void *optval_, size_t *optvallen_)

View File

@ -283,6 +283,14 @@ void test_ctx_option_blocky ()
test_context_socket_close (router); test_context_socket_close (router);
} }
void test_ctx_option_invalid ()
{
TEST_ASSERT_EQUAL_INT (-1, zmq_ctx_set (get_test_context (), -1, 0));
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) int main (void)
{ {
setup_test_environment (); setup_test_environment ();
@ -297,5 +305,6 @@ int main (void)
RUN_TEST (test_ctx_thread_opts); RUN_TEST (test_ctx_thread_opts);
RUN_TEST (test_ctx_zero_copy); RUN_TEST (test_ctx_zero_copy);
RUN_TEST (test_ctx_option_blocky); RUN_TEST (test_ctx_option_blocky);
RUN_TEST (test_ctx_option_invalid);
return UNITY_END (); return UNITY_END ();
} }