summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Hintjens <ph@imatix.com>2010-08-07 20:55:07 +0200
committerPieter Hintjens <ph@imatix.com>2010-08-07 20:55:07 +0200
commit677b3d906acc97c26855bdc31126492878ad6292 (patch)
tree0dab6e89bbf387a100cb1d6c69d8773925b05da2
parentb579aa9510fe6897735ba2aae5db399ef89ad573 (diff)
Added not-null assertions on pointer arguments in C API functions
* zmq_term * zmq_socket * zmq_close * zmq_setsockopt * zmq_getsockopt * zmq_bind * zmq_connect * zmq_send * zmq_recv * zmq_poll * zmq_device * zmq_stopwatch_stop
-rw-r--r--src/zmq.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/zmq.cpp b/src/zmq.cpp
index 75e2e7f..32862bb 100644
--- a/src/zmq.cpp
+++ b/src/zmq.cpp
@@ -275,6 +275,7 @@ int zmq_term (void *ctx_)
int rc = ((zmq::ctx_t*) ctx_)->term ();
int en = errno;
+ zmq_assert (ctx_);
#if defined ZMQ_HAVE_OPENPGM
// Shut down the OpenPGM library.
if (pgm_shutdown () != TRUE)
@@ -287,11 +288,13 @@ int zmq_term (void *ctx_)
void *zmq_socket (void *ctx_, int type_)
{
+ zmq_assert (ctx_);
return (void*) (((zmq::ctx_t*) ctx_)->create_socket (type_));
}
int zmq_close (void *s_)
{
+ zmq_assert (s_);
((zmq::socket_base_t*) s_)->close ();
return 0;
}
@@ -299,33 +302,39 @@ int zmq_close (void *s_)
int zmq_setsockopt (void *s_, int option_, const void *optval_,
size_t optvallen_)
{
+ zmq_assert (s_);
return (((zmq::socket_base_t*) s_)->setsockopt (option_, optval_,
optvallen_));
}
int zmq_getsockopt (void *s_, int option_, void *optval_, size_t *optvallen_)
{
+ zmq_assert (s_);
return (((zmq::socket_base_t*) s_)->getsockopt (option_, optval_,
optvallen_));
}
int zmq_bind (void *s_, const char *addr_)
{
+ zmq_assert (s_);
return (((zmq::socket_base_t*) s_)->bind (addr_));
}
int zmq_connect (void *s_, const char *addr_)
{
+ zmq_assert (s_);
return (((zmq::socket_base_t*) s_)->connect (addr_));
}
int zmq_send (void *s_, zmq_msg_t *msg_, int flags_)
{
+ zmq_assert (s_);
return (((zmq::socket_base_t*) s_)->send (msg_, flags_));
}
int zmq_recv (void *s_, zmq_msg_t *msg_, int flags_)
{
+ zmq_assert (s_);
return (((zmq::socket_base_t*) s_)->recv (msg_, flags_));
}
@@ -337,6 +346,8 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
defined ZMQ_HAVE_HPUX || defined ZMQ_HAVE_AIX ||\
defined ZMQ_HAVE_NETBSD
+ zmq_assert (items_);
+
pollfd *pollfds = (pollfd*) malloc (nitems_ * sizeof (pollfd));
zmq_assert (pollfds);
int npollfds = 0;
@@ -648,6 +659,9 @@ int zmq_errno ()
int zmq_device (int device_, void *insocket_, void *outsocket_)
{
+ zmq_assert (insocket_);
+ zmq_assert (outsocket_);
+
switch (device_) {
case ZMQ_FORWARDER:
return zmq::forwarder ((zmq::socket_base_t*) insocket_,
@@ -721,6 +735,7 @@ unsigned long zmq_stopwatch_stop (void *watch_)
{
uint64_t end = now ();
uint64_t start = *(uint64_t*) watch_;
+ zmq_assert (watch_);
free (watch_);
return (unsigned long) (end - start);
}