Commit 9c2740d9 authored by Uli Köhler's avatar Uli Köhler

Minor fixes to doc ; added zmq_msg_init_data() assert preventing deferred segfault

parent bcfe863f
...@@ -58,7 +58,7 @@ int zmq::msg_t::init_size (size_t size_) ...@@ -58,7 +58,7 @@ int zmq::msg_t::init_size (size_t size_)
u.lmsg.flags = 0; u.lmsg.flags = 0;
u.lmsg.content = u.lmsg.content =
(content_t*) malloc (sizeof (content_t) + size_); (content_t*) malloc (sizeof (content_t) + size_);
if (!u.lmsg.content) { if (unlikely (!u.lmsg.content)) {
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;
} }
...@@ -75,7 +75,9 @@ int zmq::msg_t::init_size (size_t size_) ...@@ -75,7 +75,9 @@ int zmq::msg_t::init_size (size_t size_)
int zmq::msg_t::init_data (void *data_, size_t size_, msg_free_fn *ffn_, int zmq::msg_t::init_data (void *data_, size_t size_, msg_free_fn *ffn_,
void *hint_) void *hint_)
{ {
// Initialize constant message if there's no need to deallocate // If data is NULL and size is not 0, a segfault
// would occur once the data is accessed
assert (data_ != NULL || size_ == 0);
if(ffn_ == NULL) { if(ffn_ == NULL) {
u.cmsg.type = type_cmsg; u.cmsg.type = type_cmsg;
u.cmsg.flags = 0; u.cmsg.flags = 0;
......
...@@ -44,7 +44,7 @@ namespace zmq ...@@ -44,7 +44,7 @@ namespace zmq
{ {
public: public:
// Mesage flags. // Message flags.
enum enum
{ {
more = 1, more = 1,
...@@ -105,8 +105,11 @@ namespace zmq ...@@ -105,8 +105,11 @@ namespace zmq
enum type_t enum type_t
{ {
type_min = 101, type_min = 101,
// VSM messages store the content in the message itself
type_vsm = 101, type_vsm = 101,
// LMSG messages store the content in malloc-ed memory
type_lmsg = 102, type_lmsg = 102,
// Delimiter messages are used in envelopes
type_delimiter = 103, type_delimiter = 103,
// CMSG messages point to constant data // CMSG messages point to constant data
type_cmsg = 104, type_cmsg = 104,
......
...@@ -539,7 +539,7 @@ int zmq_recviov (void *s_, iovec *a_, size_t *count_, int flags_) ...@@ -539,7 +539,7 @@ int zmq_recviov (void *s_, iovec *a_, size_t *count_, int flags_)
a_[i].iov_len = zmq_msg_size (&msg); a_[i].iov_len = zmq_msg_size (&msg);
a_[i].iov_base = malloc(a_[i].iov_len); a_[i].iov_base = malloc(a_[i].iov_len);
if (!a_[i].iov_base) { if (unlikely (!a_[i].iov_base)) {
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;
} }
......
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