Commit a457be31 authored by Chuck Remes's avatar Chuck Remes

Merge pull request #246 from pieterh/arguments

Return EFAULT if required arguments are null
parents 9321dfb8 8a497e2f
......@@ -9,7 +9,7 @@ zmq_msg_size - retrieve message content size in bytes
SYNOPSIS
--------
*size_t zmq_msg_size (zmq_msg_t '*msg');*
*ssize_t zmq_msg_size (zmq_msg_t '*msg');*
DESCRIPTION
......@@ -29,7 +29,15 @@ message content in bytes.
ERRORS
------
No errors are defined.
The _zmq_msg_size()_ function shall return a positive integer (0 or higher)
if successful. Otherwise it shall return `-1` and set 'errno' to one of the
values defined below.
ERRORS
------
*EFAULT*::
The provided 'msg' was NULL.
SEE ALSO
......@@ -44,5 +52,5 @@ linkzmq:zmq[7]
AUTHORS
-------
This 0MQ manual page was written by Martin Sustrik <sustrik@250bpm.com> and
Martin Lucina <mato@kotelna.sk>.
This 0MQ manual page was written by Martin Sustrik <sustrik@250bpm.com>,
Martin Lucina <mato@kotelna.sk>, and Pieter Hintjens <ph@imatix.com>.
......@@ -29,6 +29,7 @@ extern "C" {
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#if defined _WIN32
#include <winsock2.h>
#endif
......@@ -167,14 +168,13 @@ ZMQ_EXPORT int zmq_msg_close (zmq_msg_t *msg);
ZMQ_EXPORT int zmq_msg_move (zmq_msg_t *dest, zmq_msg_t *src);
ZMQ_EXPORT int zmq_msg_copy (zmq_msg_t *dest, zmq_msg_t *src);
ZMQ_EXPORT void *zmq_msg_data (zmq_msg_t *msg);
ZMQ_EXPORT size_t zmq_msg_size (zmq_msg_t *msg);
ZMQ_EXPORT ssize_t zmq_msg_size (zmq_msg_t *msg);
ZMQ_EXPORT int zmq_msg_more (zmq_msg_t *msg);
ZMQ_EXPORT int zmq_msg_get (zmq_msg_t *msg, int option, void *optval,
size_t *optvallen);
ZMQ_EXPORT int zmq_msg_set (zmq_msg_t *msg, int option, const void *optval,
size_t *optvallen);
/******************************************************************************/
/* 0MQ infrastructure (a.k.a. context) initialisation & termination. */
/******************************************************************************/
......
/*
Copyright (c) 2007-2012 iMatix Corporation
Copyright (c) 2009-2011 250bpm s.r.o.
Copyright (c) 2007-2009 iMatix Corporation
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
This file is part of 0MQ.
......@@ -35,7 +35,7 @@
#include <pthread.h>
#endif
static size_t message_size;
static ssize_t message_size;
static int roundtrip_count;
#if defined ZMQ_HAVE_WINDOWS
......
/*
Copyright (c) 2007-2012 iMatix Corporation
Copyright (c) 2009-2011 250bpm s.r.o.
Copyright (c) 2007-2009 iMatix Corporation
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
This file is part of 0MQ.
......@@ -36,7 +36,7 @@
#endif
static int message_count;
static size_t message_size;
static ssize_t message_size;
#if defined ZMQ_HAVE_WINDOWS
static unsigned int __stdcall worker (void *ctx_)
......
/*
Copyright (c) 2007-2012 iMatix Corporation
Copyright (c) 2009-2011 250bpm s.r.o.
Copyright (c) 2007-2009 iMatix Corporation
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
This file is part of 0MQ.
......@@ -28,7 +28,7 @@ int main (int argc, char *argv [])
{
const char *bind_to;
int roundtrip_count;
size_t message_size;
ssize_t message_size;
void *ctx;
void *s;
int rc;
......
/*
Copyright (c) 2007-2012 iMatix Corporation
Copyright (c) 2009-2011 250bpm s.r.o.
Copyright (c) 2007-2009 iMatix Corporation
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
This file is part of 0MQ.
......@@ -28,7 +28,7 @@ int main (int argc, char *argv [])
{
const char *bind_to;
int message_count;
size_t message_size;
ssize_t message_size;
void *ctx;
void *s;
int rc;
......
/*
Copyright (c) 2007-2012 iMatix Corporation
Copyright (c) 2009-2011 250bpm s.r.o.
Copyright (c) 2007-2009 iMatix Corporation
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
This file is part of 0MQ.
......@@ -29,7 +29,7 @@ int main (int argc, char *argv [])
{
const char *connect_to;
int roundtrip_count;
size_t message_size;
ssize_t message_size;
void *ctx;
void *s;
int rc;
......
......@@ -502,17 +502,29 @@ int zmq_recviov (void *s_, iovec *a_, size_t *count_, int flags_)
int zmq_msg_init (zmq_msg_t *msg_)
{
if (!msg_) {
errno = EFAULT;
return -1;
}
return ((zmq::msg_t*) msg_)->init ();
}
int zmq_msg_init_size (zmq_msg_t *msg_, size_t size_)
{
if (!msg_) {
errno = EFAULT;
return -1;
}
return ((zmq::msg_t*) msg_)->init_size (size_);
}
int zmq_msg_init_data (zmq_msg_t *msg_, void *data_, size_t size_,
zmq_free_fn *ffn_, void *hint_)
{
if (!msg_) {
errno = EFAULT;
return -1;
}
return ((zmq::msg_t*) msg_)->init_data (data_, size_, ffn_, hint_);
}
......@@ -544,26 +556,46 @@ int zmq_msg_recv (zmq_msg_t *msg_, void *s_, int flags_)
int zmq_msg_close (zmq_msg_t *msg_)
{
if (!msg_) {
errno = EFAULT;
return -1;
}
return ((zmq::msg_t*) msg_)->close ();
}
int zmq_msg_move (zmq_msg_t *dest_, zmq_msg_t *src_)
{
if (!dest_ || !src_) {
errno = EFAULT;
return -1;
}
return ((zmq::msg_t*) dest_)->move (*(zmq::msg_t*) src_);
}
int zmq_msg_copy (zmq_msg_t *dest_, zmq_msg_t *src_)
{
if (!dest_ || !src_) {
errno = EFAULT;
return -1;
}
return ((zmq::msg_t*) dest_)->copy (*(zmq::msg_t*) src_);
}
void *zmq_msg_data (zmq_msg_t *msg_)
{
if (!msg_) {
errno = EFAULT;
return NULL;
}
return ((zmq::msg_t*) msg_)->data ();
}
size_t zmq_msg_size (zmq_msg_t *msg_)
ssize_t zmq_msg_size (zmq_msg_t *msg_)
{
if (!msg_) {
errno = EFAULT;
return -1;
}
return ((zmq::msg_t*) msg_)->size ();
}
......@@ -615,6 +647,10 @@ int zmq_msg_set (zmq_msg_t *msg_, int option_, const void *optval_,
int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
{
if (!items_) {
errno = EFAULT;
return -1;
}
#if defined ZMQ_POLL_BASED_ON_POLL
if (unlikely (nitems_ < 0)) {
errno = EINVAL;
......@@ -633,12 +669,6 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
return usleep (timeout_ * 1000);
#endif
}
if (!items_) {
errno = EFAULT;
return -1;
}
zmq::clock_t clock;
uint64_t now = 0;
uint64_t end = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment