Ok, this is a sanity check of my work. I've attached the beginnings of adding error checking around the zmalloc call - this is not tested and should not be pushed into the tree! I'm just wanting to make sure I'm heading in the right direction and that this looks like something that will be accepted.
I'm trying to break each changeset out by the class it affects. This reaches out into any classes that use the main class of course, but those changes *should* be minimal in most cases. Anyway - patches are attached. Again - these should not be applied, just given a quick once over to make sure I'm not missing the boat. Thanks, AJ On Tue, Sep 27, 2011 at 02:02:30PM -0500, Pieter Hintjens wrote: > On Tue, Sep 27, 2011 at 10:14 AM, Steven McCoy <[email protected]> wrote: > > > Wasn't there a discussion on /. recently about this, Dijkstra's view > > tends to be taken out of context because it was in regard to Pascal > > which has an alternative method of breaking out of multiple loops. > > I count 160 instances of goto in OpenPGM, all for error cases. > > Totally agreed. In OpenAMQ I count several hundred gotos, all in error > cases. It's a valid pattern IME, if it makes error handling simpler. -- AJ Lewis Software Engineer Quantum Corporation Work: 651 688-4346 ---------------------------------------------------------------------- The information contained in this transmission may be confidential. Any disclosure, copying, or further distribution of confidential information is not permitted unless such privilege is explicitly granted in writing by Quantum. Quantum reserves the right to have electronic communications, including email and attachments, sent across its networks filtered through anti virus and spam software programs and retain such messages in order to comply with applicable data security and retention requirements. Quantum is not responsible for the proper and complete transmission of the substance of this communication or for any delay in its receipt.
>From 0190ae6b42f0cb78b025169144e865e22ea4bf98 Mon Sep 17 00:00:00 2001 From: AJ Lewis <[email protected]> Date: Mon, 12 Sep 2011 12:06:00 -0500 Subject: [PATCH 1/3] Add a new #define option that behaves the same as _ZMALLOC_DEBUG: _ZMALLOC_PEDANTIC This allows allocation errors to propagate up the call stack rather than getting trapped by safe_malloc() and causing an abort() call. Signed-off-by: AJ Lewis <[email protected]> --- include/czmq_prelude.h | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/czmq_prelude.h b/include/czmq_prelude.h index 5b2cafe..7197ca2 100644 --- a/include/czmq_prelude.h +++ b/include/czmq_prelude.h @@ -468,8 +468,9 @@ static inline void * // Define _ZMALLOC_DEBUG if you need to trace memory leaks using e.g. mtrace, // otherwise all allocations will claim to come from zfl_prelude.h. For best // results, compile all classes so you see dangling object allocations. -// -#ifdef _ZMALLOC_DEBUG +// _ZMALLOC_PEDANTIC does the same thing, but its intention is to propagate +// out of memory condition back up the call stack. +#if defined _ZMALLOC_DEBUG || _ZMALLOC_PEDANTIC # define zmalloc(size) calloc(1,(size)) #else # define zmalloc(size) safe_malloc((size), __FILE__, __LINE__, CZMQ_ASSERT_SANE_FUNCTION) -- 1.7.7.rc3.4.g8d714
>From 5dc1e516ce98770ccd7b4a339d559805b8bb8c7a Mon Sep 17 00:00:00 2001 From: AJ Lewis <[email protected]> Date: Mon, 12 Sep 2011 12:13:09 -0500 Subject: [PATCH 2/3] Deal with zmalloc failing to allocate memory in the zctx module. Check the return of zmalloc in zctx_new() and zctx_shadow(). Deal with the cases where these two functions are called elsewhere in the code. Signed-off-by: AJ Lewis <[email protected]> --- src/zctx.c | 13 +++++++++++-- src/zframe.c | 1 + src/zloop.c | 1 + src/zsocket.c | 1 + src/zsockopt.c | 2 ++ src/zstr.c | 1 + src/zthread.c | 4 ++++ 7 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/zctx.c b/src/zctx.c index 0abfe87..8e0dd08 100644 --- a/src/zctx.c +++ b/src/zctx.c @@ -96,6 +96,10 @@ zctx_new (void) *self; self = (zctx_t *) zmalloc (sizeof (zctx_t)); + if (!self) { + goto end; + } + self->sockets = zlist_new (); self->iothreads = 1; self->main = TRUE; @@ -110,6 +114,8 @@ zctx_new (void) sigaction (SIGTERM, &action, NULL); #endif +end: + return self; } @@ -146,8 +152,10 @@ zctx_shadow (zctx_t *ctx) // Shares same 0MQ context but has its own list of sockets so that // we create, use, and destroy sockets only within a single thread. self = (zctx_t *) zmalloc (sizeof (zctx_t)); - self->sockets = zlist_new (); - self->context = ctx->context; + if (self) { + self->sockets = zlist_new (); + self->context = ctx->context; + } return self; } @@ -230,6 +238,7 @@ zctx_test (Bool verbose) // Create a context with many busy sockets, destroy it ctx = zctx_new (); + assert (ctx); zctx_set_iothreads (ctx, 1); zctx_set_linger (ctx, 5); // 5 msecs void *s1 = zctx__socket_new (ctx, ZMQ_PAIR); diff --git a/src/zframe.c b/src/zframe.c index 83a69a6..23d8681 100644 --- a/src/zframe.c +++ b/src/zframe.c @@ -327,6 +327,7 @@ zframe_test (Bool verbose) // @selftest zctx_t *ctx = zctx_new (); + assert (ctx); void *output = zsocket_new (ctx, ZMQ_PAIR); zsocket_bind (output, "inproc://zframe.test"); diff --git a/src/zloop.c b/src/zloop.c index 75e647f..5413a9a 100644 --- a/src/zloop.c +++ b/src/zloop.c @@ -407,6 +407,7 @@ zloop_test (Bool verbose) // @selftest zctx_t *ctx = zctx_new (); + assert(ctx); void *output = zsocket_new (ctx, ZMQ_PAIR); zsocket_bind (output, "inproc://zloop.test"); diff --git a/src/zsocket.c b/src/zsocket.c index 408cad0..76674e7 100644 --- a/src/zsocket.c +++ b/src/zsocket.c @@ -156,6 +156,7 @@ zsocket_test (Bool verbose) // @selftest zctx_t *ctx = zctx_new (); + assert (ctx); // Create a detached thread, let it run char *interf = "*"; diff --git a/src/zsockopt.c b/src/zsockopt.c index 98a9dd6..0abd7b9 100644 --- a/src/zsockopt.c +++ b/src/zsockopt.c @@ -1225,6 +1225,8 @@ zsockopt_test (Bool verbose) // @selftest zctx_t *ctx = zctx_new (); + assert(ctx); + void *socket; #if (ZMQ_VERSION_MAJOR == 2) socket = zsocket_new (ctx, ZMQ_SUB); diff --git a/src/zstr.c b/src/zstr.c index ba5c9cd..5ad6875 100644 --- a/src/zstr.c +++ b/src/zstr.c @@ -159,6 +159,7 @@ zstr_test (Bool verbose) // @selftest zctx_t *ctx = zctx_new (); + assert(ctx); void *output = zsocket_new (ctx, ZMQ_PAIR); zsocket_bind (output, "inproc://zstr.test"); diff --git a/src/zthread.c b/src/zthread.c index 43152b2..a2a7743 100644 --- a/src/zthread.c +++ b/src/zthread.c @@ -182,6 +182,7 @@ zthread_fork (zctx_t *ctx, zthread_attached_fn *thread_fn, void *args) shim->attached = thread_fn; shim->args = args; shim->ctx = zctx_shadow (ctx); + assert (shim->ctx); // Connect child pipe to our pipe shim->pipe = zsocket_new (shim->ctx, ZMQ_PAIR); @@ -203,6 +204,8 @@ s_test_detached (void *args) { // Create a socket to check it'll be automatically deleted zctx_t *ctx = zctx_new (); + assert (ctx); + void *push = zsocket_new (ctx, ZMQ_PUSH); zctx_destroy (&ctx); return NULL; @@ -227,6 +230,7 @@ zthread_test (Bool verbose) // @selftest zctx_t *ctx = zctx_new (); + assert (ctx); // Create a detached thread, let it run zthread_new (s_test_detached, NULL); -- 1.7.7.rc3.4.g8d714
>From 43eba3aa9a814410104e70b21d76dd8e86682b95 Mon Sep 17 00:00:00 2001 From: AJ Lewis <[email protected]> Date: Tue, 13 Sep 2011 12:02:53 -0500 Subject: [PATCH 3/3] Deal with zmalloc failing to allocate memory in the zframe module. Check the return of zmalloc in zframe_new(). Deal with the cases where this function is called elsewhere in the code (and corresponding changes related to those changes). Refactor zmsg_addstr()/zmsg_pushstr() to use a common base function. Currently, zframe_send() does *not* destroy the frame on error, even if ZFRAME_REUSE is not set. There is a FIXME comment in the zmsg module for zmsg_load(). It currently just breaks out of the loop like all other error conditions if zmsg_add() fails, but this seems like it could cause silent data corruption (in all cases), so it should be looked at when going through the zmsg module later. Signed-off-by: AJ Lewis <[email protected]> --- include/zframe.h | 5 +- include/zmsg.h | 23 +++-- src/zframe.c | 82 ++++++++++++++---- src/zmsg.c | 248 ++++++++++++++++++++++++++++++++++++++---------------- 4 files changed, 255 insertions(+), 103 deletions(-) diff --git a/include/zframe.h b/include/zframe.h index bb3318a..a904699 100644 --- a/include/zframe.h +++ b/include/zframe.h @@ -57,8 +57,9 @@ zframe_t * zframe_t * zframe_recv_nowait (void *socket); -// Send a frame to a socket, destroy frame after sending -void +// Send a frame to a socket, destroy frame after sending. Returns +// non-zero error code on failure. +int zframe_send (zframe_t **self_p, void *socket, int flags); // Return number of bytes in frame data diff --git a/include/zmsg.h b/include/zmsg.h index be4844d..22ac640 100644 --- a/include/zmsg.h +++ b/include/zmsg.h @@ -71,20 +71,24 @@ zframe_t * void zmsg_add (zmsg_t *self, zframe_t *frame); -// Push block of memory as new frame to front of message -void +// Push block of memory as new frame to front of message. Returns +// non-zero error code on failure +int zmsg_pushmem (zmsg_t *self, const void *src, size_t size); -// Push block of memory as new frame to end of message -void +// Push block of memory as new frame to end of message. Returns +// non-zero error code on failure +int zmsg_addmem (zmsg_t *self, const void *src, size_t size); -// Push string as new frame to front of message -void +// Push string as new frame to front of message. Returns non-zero +// error code on failure +int zmsg_pushstr (zmsg_t *self, const char *format, ...); -// Push string as new frame to end of message -void +// Push string as new frame to end of message. Returns non-zero +// error code on failure +int zmsg_addstr (zmsg_t *self, const char *format, ...); // Pop frame off front of message, return as fresh string @@ -93,7 +97,8 @@ char * // Push frame to front of message, before first frame // Pushes an empty frame in front of frame -void +// Returns non-zero error code on failure +int zmsg_wrap (zmsg_t *self, zframe_t *frame); // Pop frame off front of message, caller now owns frame diff --git a/src/zframe.c b/src/zframe.c index 23d8681..69d00c1 100644 --- a/src/zframe.c +++ b/src/zframe.c @@ -62,6 +62,10 @@ zframe_new (const void *data, size_t size) *self; self = (zframe_t *) zmalloc (sizeof (zframe_t)); + if (!self) { + goto end; + } + if (size) { zmq_msg_init_size (&self->zmsg, size); if (data) @@ -70,6 +74,7 @@ zframe_new (const void *data, size_t size) else zmq_msg_init (&self->zmsg); +end: return self; } @@ -100,11 +105,13 @@ zframe_recv (void *socket) { assert (socket); zframe_t *self = zframe_new (NULL, 0); - if (zmq_recvmsg (socket, &self->zmsg, 0) < 0) { - zframe_destroy (&self); - return NULL; // Interrupted or terminated + if (self) { + if (zmq_recvmsg (socket, &self->zmsg, 0) < 0) { + zframe_destroy (&self); + return NULL; // Interrupted or terminated + } + self->more = zsockopt_rcvmore (socket); } - self->more = zsockopt_rcvmore (socket); return self; } @@ -118,37 +125,71 @@ zframe_recv_nowait (void *socket) { assert (socket); zframe_t *self = zframe_new (NULL, 0); - if (zmq_recvmsg (socket, &self->zmsg, ZMQ_DONTWAIT) < 0) { - zframe_destroy (&self); - return NULL; // Interrupted or terminated + if (self) { + if (zmq_recvmsg (socket, &self->zmsg, ZMQ_DONTWAIT) < 0) { + zframe_destroy (&self); + return NULL; // Interrupted or terminated + } + self->more = zsockopt_rcvmore (socket); } - self->more = zsockopt_rcvmore (socket); return self; } // -------------------------------------------------------------------------- -// Send frame to socket, destroy after sending unless ZFRAME_REUSE is set. +// Send frame to socket, destroy after sending unless ZFRAME_REUSE is +// set or the attempt to send the message errors out. -void +int zframe_send (zframe_t **self_p, void *socket, int flags) { + int error = 0; + assert (socket); assert (self_p); if (*self_p) { + int rc = 0; zframe_t *self = *self_p; if (flags & ZFRAME_REUSE) { zmq_msg_t copy; - zmq_msg_init (©); - zmq_msg_copy (©, &self->zmsg); - zmq_sendmsg (socket, ©, (flags & ZFRAME_MORE)? ZMQ_SNDMORE: 0); - zmq_msg_close (©); + rc = zmq_msg_init (©); + // No error conditions currently defined for zmq_msg_init() + assert (rc == 0); + + rc = zmq_msg_copy (©, &self->zmsg); + if (rc == -1) { + error = errno; + goto end; + } + + rc = zmq_sendmsg (socket, ©, + (flags & ZFRAME_MORE)? ZMQ_SNDMORE: 0); + if (rc == -1) { + error = errno; + goto end; + } + + rc = zmq_msg_close (©); + // Any errors possible should have been caught previously + assert(rc == 0); } else { - zmq_sendmsg (socket, &self->zmsg, (flags & ZFRAME_MORE)? ZMQ_SNDMORE: 0); + rc = zmq_sendmsg (socket, &self->zmsg, + (flags & ZFRAME_MORE)? ZMQ_SNDMORE: 0); + if (rc == -1) { + // FIXME: Should we destroy the frame anyway here? + error = errno; + goto end; + } zframe_destroy (self_p); } + } else { + error = EINVAL; } + +end: + + return error; } @@ -324,6 +365,7 @@ int zframe_test (Bool verbose) { printf (" * zframe: "); + int rc; // @selftest zctx_t *ctx = zctx_new (); @@ -338,12 +380,14 @@ zframe_test (Bool verbose) int frame_nbr; for (frame_nbr = 0; frame_nbr < 5; frame_nbr++) { zframe_t *frame = zframe_new ("Hello", 5); - zframe_send (&frame, output, ZFRAME_MORE); + rc = zframe_send (&frame, output, ZFRAME_MORE); + assert (rc == 0); } // Send same frame five times, test ZFRAME_REUSE zframe_t *frame = zframe_new ("Hello", 5); for (frame_nbr = 0; frame_nbr < 5; frame_nbr++) { - zframe_send (&frame, output, ZFRAME_MORE + ZFRAME_REUSE); + rc = zframe_send (&frame, output, ZFRAME_MORE + ZFRAME_REUSE); + assert (rc == 0); } assert (frame); zframe_t *copy = zframe_dup (frame); @@ -356,6 +400,7 @@ zframe_test (Bool verbose) // Send END frame frame = zframe_new ("NOT", 3); + assert(frame); zframe_reset (frame, "END", 3); char *string = zframe_strhex (frame); assert (streq (string, "454E44")); @@ -363,7 +408,8 @@ zframe_test (Bool verbose) string = zframe_strdup (frame); assert (streq (string, "END")); free (string); - zframe_send (&frame, output, 0); + rc = zframe_send (&frame, output, 0); + assert(rc == 0); // Read and count until we receive END frame_nbr = 0; diff --git a/src/zmsg.c b/src/zmsg.c index 6381e50..02a67a5 100644 --- a/src/zmsg.c +++ b/src/zmsg.c @@ -123,8 +123,10 @@ zmsg_send (zmsg_t **self_p, void *socket) if (self) { zframe_t *frame = (zframe_t *) zlist_pop (self->frames); while (frame) { - zframe_send (&frame, socket, - zlist_size (self->frames)? ZFRAME_MORE: 0); + int rc; + rc = zframe_send (&frame, socket, + zlist_size (self->frames)? ZFRAME_MORE: 0); + assert(rc == 0); frame = (zframe_t *) zlist_pop (self->frames); } zmsg_destroy (self_p); @@ -200,80 +202,119 @@ zmsg_add (zmsg_t *self, zframe_t *frame) // -------------------------------------------------------------------------- // Push block of memory to front of message, as a new frame. -void +int zmsg_pushmem (zmsg_t *self, const void *src, size_t size) { assert (self); + int error = 0; zframe_t *frame = zframe_new (src, size); - self->content_size += size; - zlist_push (self->frames, frame); + if (frame) { + self->content_size += size; + zlist_push (self->frames, frame); + } else { + error = ENOMEM; + } + return error; } // -------------------------------------------------------------------------- // Add block of memory to the end of the message, as a new frame. -void +int zmsg_addmem (zmsg_t *self, const void *src, size_t size) { assert (self); + int error = 0; zframe_t *frame = zframe_new (src, size); - self->content_size += size; - zlist_append (self->frames, frame); + if (frame) { + self->content_size += size; + zlist_append (self->frames, frame); + } else { + error = ENOMEM; + } + return error; } +// -------------------------------------------------------------------------- +// Handle the mechanics of pushing the string frame into the list - the list +// function passed in determines how the frame containing the string +// enters the list -// -------------------------------------------------------------------------- -// Push string as new frame to front of message - -void -zmsg_pushstr (zmsg_t *self, const char *format, ...) +int zmsg_add_str_to_framelist (void (*list_fxn)(zlist_t *, void *), + zmsg_t *self, const char *format, va_list argptr) { + assert (list_fxn); assert (self); assert (format); - // Format string into buffer - va_list argptr; - va_start (argptr, format); + int error = 0; int size = 255 + 1; char *string = (char *) malloc (size); + if (!string) { + error = ENOMEM; + goto end; + } + int required = vsnprintf (string, size, format, argptr); if (required >= size) { + char *tmpstring; size = required + 1; - string = (char *) realloc (string, size); + tmpstring = (char *) realloc (string, size); + if (!tmpstring) { + error = ENOMEM; + goto end; + } + string = tmpstring; vsnprintf (string, size, format, argptr); + + self->content_size += strlen (string); + zframe_t *frame = zframe_new (string, strlen (string)); + if (!frame) { + error = ENOMEM; + goto end; + } + + list_fxn (self->frames, frame); } - va_end (argptr); + end: - self->content_size += strlen (string); - zlist_push (self->frames, zframe_new (string, strlen (string))); free (string); + return error; +} + + + +// -------------------------------------------------------------------------- +// Push string as new frame to front of message + +int zmsg_pushstr(zmsg_t *self, const char *format, ...) +{ + assert (format); + va_list argptr; + va_start (argptr, format); + + int error = zmsg_add_str_to_framelist(&zlist_push, self, format, argptr); + va_end(argptr); + + return error; } // -------------------------------------------------------------------------- // Push string as new frame to end of message -void +int zmsg_addstr (zmsg_t *self, const char *format, ...) { - assert (self); assert (format); - // Format string into buffer va_list argptr; va_start (argptr, format); - int size = 255 + 1; - char *string = (char *) malloc (size); - int required = vsnprintf (string, size, format, argptr); - if (required >= size) { - size = required + 1; - string = (char *) realloc (string, size); - vsnprintf (string, size, format, argptr); - } + + int error = zmsg_add_str_to_framelist (&zlist_append, self, format, argptr); + va_end (argptr); - self->content_size += strlen (string); - zlist_append (self->frames, zframe_new (string, strlen (string))); - free (string); + return error; } @@ -299,13 +340,17 @@ zmsg_popstr (zmsg_t *self) // Push frame plus empty frame to front of message, before first frame. // Message takes ownership of frame, will destroy it when message is sent. -void +int zmsg_wrap (zmsg_t *self, zframe_t *frame) { assert (self); assert (frame); - zmsg_pushmem (self, "", 0); - zmsg_push (self, frame); + int error = 0; + error = zmsg_pushmem (self, "", 0); + if (!error) { + zmsg_push (self, frame); + } + return error; } @@ -404,7 +449,8 @@ zmsg_save (zmsg_t *self, FILE *file) // -------------------------------------------------------------------------- // Load/append an open file into message, create new message if // null message provided. - +// FIXME: Not sure what to do with errors in this one...break seems +// wrong - silent corrupt messages are possible. zmsg_t * zmsg_load (zmsg_t *self, FILE *file) { @@ -417,10 +463,14 @@ zmsg_load (zmsg_t *self, FILE *file) size_t rc = fread (&frame_size, sizeof (frame_size), 1, file); if (rc == 1) { zframe_t *frame = zframe_new (NULL, frame_size); - rc = fread (zframe_data (frame), frame_size, 1, file); - if (frame_size > 0 && rc != 1) - break; // Unable to read properly, quit - zmsg_add (self, frame); + if (frame) { + rc = fread (zframe_data (frame), frame_size, 1, file); + if (frame_size > 0 && rc != 1) + break; // Unable to read properly, quit + zmsg_add (self, frame); + } else { + break; + } } else break; // Unable to read properly, quit @@ -508,26 +558,37 @@ zmsg_decode (byte *buffer, size_t buffer_size) while (source < limit) { size_t frame_size = *source++; if (frame_size == ZMSG_SHORT_LEN) { - if (source > limit - 2) - return NULL; + if (source > limit - 2) { + zmsg_destroy (&self); + break; + } frame_size = (source [0] << 8) + source [1]; source += 2; } else if (frame_size == ZMSG_LONG_LEN) { - if (source > limit - 4) - return NULL; + if (source > limit - 4) { + zmsg_destroy (&self); + break; + } frame_size = (source [0] << 24) + (source [1] << 16) + (source [2] << 8) + source [3]; source += 4; } - if (source > limit - frame_size) - return NULL; + if (source > limit - frame_size) { + zmsg_destroy (&self); + break; + } zframe_t *frame = zframe_new (source, frame_size); - zmsg_add (self, frame); - source += frame_size; + if (frame) { + zmsg_add (self, frame); + source += frame_size; + } else { + zmsg_destroy (&self); + break; + } } return self; } @@ -535,17 +596,30 @@ zmsg_decode (byte *buffer, size_t buffer_size) // -------------------------------------------------------------------------- // Create copy of message, as new message object +// FIXME: It would be nice if this function returned the actual error +// up the stack rather than just passing back NULL on error. zmsg_t * zmsg_dup (zmsg_t *self) { assert (self); - zmsg_t *copy = zmsg_new (); + int rc = 0; + zmsg_t *copy = NULL; zframe_t *frame = zmsg_first (self); + if (!frame) { + goto end; + } + copy = zmsg_new (); while (frame) { - zmsg_addmem (copy, zframe_data (frame), zframe_size (frame)); + rc = zmsg_addmem (copy, zframe_data (frame), zframe_size (frame)); + if (rc) { + zmsg_destroy(©); + goto end; + } frame = zmsg_next (self); } + +end: return copy; } @@ -579,8 +653,10 @@ zmsg_test (Bool verbose) { printf (" * zmsg: "); + int rc = 0; // @selftest zctx_t *ctx = zctx_new (); + assert (ctx); void *output = zsocket_new (ctx, ZMQ_PAIR); zsocket_bind (output, "inproc://zmsg.test"); @@ -590,6 +666,7 @@ zmsg_test (Bool verbose) // Test send and receive of single-frame message zmsg_t *msg = zmsg_new (); zframe_t *frame = zframe_new ("Hello", 5); + assert(frame); zmsg_push (msg, frame); assert (zmsg_size (msg) == 1); assert (zmsg_content_size (msg) == 5); @@ -604,17 +681,28 @@ zmsg_test (Bool verbose) // Test send and receive of multi-frame message msg = zmsg_new (); - zmsg_addmem (msg, "Frame0", 6); - zmsg_addmem (msg, "Frame1", 6); - zmsg_addmem (msg, "Frame2", 6); - zmsg_addmem (msg, "Frame3", 6); - zmsg_addmem (msg, "Frame4", 6); - zmsg_addmem (msg, "Frame5", 6); - zmsg_addmem (msg, "Frame6", 6); - zmsg_addmem (msg, "Frame7", 6); - zmsg_addmem (msg, "Frame8", 6); - zmsg_addmem (msg, "Frame9", 6); + rc = zmsg_addmem (msg, "Frame0", 6); + assert(rc == 0); + rc = zmsg_addmem (msg, "Frame1", 6); + assert(rc == 0); + rc = zmsg_addmem (msg, "Frame2", 6); + assert(rc == 0); + rc = zmsg_addmem (msg, "Frame3", 6); + assert(rc == 0); + rc = zmsg_addmem (msg, "Frame4", 6); + assert(rc == 0); + rc = zmsg_addmem (msg, "Frame5", 6); + assert(rc == 0); + rc = zmsg_addmem (msg, "Frame6", 6); + assert(rc == 0); + rc = zmsg_addmem (msg, "Frame7", 6); + assert(rc == 0); + rc = zmsg_addmem (msg, "Frame8", 6); + assert(rc == 0); + rc = zmsg_addmem (msg, "Frame9", 6); + assert(rc == 0); zmsg_t *copy = zmsg_dup (msg); + assert (copy); zmsg_send (©, output); zmsg_send (&msg, output); @@ -634,7 +722,7 @@ zmsg_test (Bool verbose) // Save to a file, read back FILE *file = fopen ("zmsg.test", "w"); assert (file); - int rc = zmsg_save (msg, file); + rc = zmsg_save (msg, file); assert (rc == 0); fclose (file); @@ -663,9 +751,12 @@ zmsg_test (Bool verbose) assert (zmsg_size (msg) == 2); assert (zmsg_content_size (msg) == 12); frame = zframe_new ("Address", 7); - zmsg_wrap (msg, frame); + assert (frame); + rc = zmsg_wrap (msg, frame); + assert (rc == 0); assert (zmsg_size (msg) == 4); - zmsg_addstr (msg, "Body"); + rc = zmsg_addstr (msg, "Body"); + assert (rc == 0); assert (zmsg_size (msg) == 5); frame = zmsg_unwrap (msg); zframe_destroy (&frame); @@ -678,15 +769,24 @@ zmsg_test (Bool verbose) // Test encoding/decoding msg = zmsg_new (); byte *blank = zmalloc (100000); - zmsg_addmem (msg, blank, 0); - zmsg_addmem (msg, blank, 1); - zmsg_addmem (msg, blank, 253); - zmsg_addmem (msg, blank, 254); - zmsg_addmem (msg, blank, 255); - zmsg_addmem (msg, blank, 256); - zmsg_addmem (msg, blank, 65535); - zmsg_addmem (msg, blank, 65536); - zmsg_addmem (msg, blank, 65537); + rc = zmsg_addmem (msg, blank, 0); + assert(rc == 0); + rc = zmsg_addmem (msg, blank, 1); + assert(rc == 0); + rc = zmsg_addmem (msg, blank, 253); + assert(rc == 0); + rc = zmsg_addmem (msg, blank, 254); + assert(rc == 0); + rc = zmsg_addmem (msg, blank, 255); + assert(rc == 0); + rc = zmsg_addmem (msg, blank, 256); + assert(rc == 0); + rc = zmsg_addmem (msg, blank, 65535); + assert(rc == 0); + rc = zmsg_addmem (msg, blank, 65536); + assert(rc == 0); + rc = zmsg_addmem (msg, blank, 65537); + assert(rc == 0); free (blank); assert (zmsg_size (msg) == 9); byte *buffer; -- 1.7.7.rc3.4.g8d714
_______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
