From 440d428153a2ac26220554a6700b6d4d5e905999 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 16 May 2018 23:14:17 +0200 Subject: [PATCH 1/6] Problem: single-argument ctor of blob_t is not marked explicit Solution: add explicit --- src/blob.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blob.hpp b/src/blob.hpp index 44de6ac8..6abc86dd 100644 --- a/src/blob.hpp +++ b/src/blob.hpp @@ -72,7 +72,7 @@ struct blob_t blob_t () : data_ (0), size_ (0), owned_ (true) {} // Creates a blob_t of a given size, with uninitialized content. - blob_t (const size_t size) : + explicit blob_t (const size_t size) : data_ ((unsigned char *) malloc (size)), size_ (size), owned_ (true) From 2120f6aced4fa203c5549642df2ecc3754feb1fb Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Thu, 17 May 2018 14:25:02 +0200 Subject: [PATCH 2/6] Problem: ypipe_t::read is called with NULL argument Solution: call check_read instead --- src/mailbox.cpp | 2 +- src/mailbox_safe.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mailbox.cpp b/src/mailbox.cpp index 8d814a03..12a55624 100644 --- a/src/mailbox.cpp +++ b/src/mailbox.cpp @@ -36,7 +36,7 @@ zmq::mailbox_t::mailbox_t () // Get the pipe into passive state. That way, if the users starts by // polling on the associated file descriptor it will get woken up when // new command is posted. - const bool ok = cpipe.read (NULL); + const bool ok = cpipe.check_read (); zmq_assert (!ok); active = false; } diff --git a/src/mailbox_safe.cpp b/src/mailbox_safe.cpp index 921481d2..3fb7acff 100644 --- a/src/mailbox_safe.cpp +++ b/src/mailbox_safe.cpp @@ -37,7 +37,7 @@ zmq::mailbox_safe_t::mailbox_safe_t (mutex_t *sync_) : sync (sync_) // Get the pipe into passive state. That way, if the users starts by // polling on the associated file descriptor it will get woken up when // new command is posted. - const bool ok = cpipe.read (NULL); + const bool ok = cpipe.check_read (); zmq_assert (!ok); } From e37fc47fb68b18ae96802b39c4be994dc2e7f5be Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Thu, 17 May 2018 14:26:02 +0200 Subject: [PATCH 3/6] Problem: return value is stored but never used Solution: add code to make non-use explicit --- src/dealer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dealer.cpp b/src/dealer.cpp index 81da60fd..62c12ad3 100644 --- a/src/dealer.cpp +++ b/src/dealer.cpp @@ -57,6 +57,8 @@ void zmq::dealer_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) rc = pipe_->write (&probe_msg_); // zmq_assert (rc) is not applicable here, since it is not a bug. + (void) rc; + pipe_->flush (); rc = probe_msg_.close (); From 22b72bb678660fca27ba0efd4f0f3e3fea364c9b Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Thu, 17 May 2018 14:34:52 +0200 Subject: [PATCH 4/6] Problem: deallocate calls release after de-allocation Solution: reduce to newly extracted function clear, which does not use the freed pointer --- src/decoder_allocators.cpp | 10 +++++++--- src/decoder_allocators.hpp | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/decoder_allocators.cpp b/src/decoder_allocators.cpp index 78eac47d..6fcdfb71 100644 --- a/src/decoder_allocators.cpp +++ b/src/decoder_allocators.cpp @@ -108,17 +108,21 @@ void zmq::shared_message_memory_allocator::deallocate () if (buf && !c->sub (1)) { std::free (buf); } - release (); + clear (); } unsigned char *zmq::shared_message_memory_allocator::release () { unsigned char *b = buf; + clear (); + return b; +} + +void zmq::shared_message_memory_allocator::clear () +{ buf = NULL; bufsize = 0; msg_content = NULL; - - return b; } void zmq::shared_message_memory_allocator::inc_ref () diff --git a/src/decoder_allocators.hpp b/src/decoder_allocators.hpp index a47ac358..ab6398b5 100644 --- a/src/decoder_allocators.hpp +++ b/src/decoder_allocators.hpp @@ -120,6 +120,8 @@ class shared_message_memory_allocator void advance_content () { msg_content++; } private: + void clear (); + unsigned char *buf; std::size_t bufsize; const std::size_t max_size; From ad781319ef7b30c6f041b0d14285feffee03cb6b Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Thu, 17 May 2018 14:58:37 +0200 Subject: [PATCH 5/6] Problem: ternary operator used with boolean literals\n\nSolution: Use comparison with 0 instead --- src/rep.cpp | 2 +- src/req.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rep.cpp b/src/rep.cpp index 1193a098..081b379c 100644 --- a/src/rep.cpp +++ b/src/rep.cpp @@ -52,7 +52,7 @@ int zmq::rep_t::xsend (msg_t *msg_) return -1; } - bool more = msg_->flags () & msg_t::more ? true : false; + bool more = (msg_->flags () & msg_t::more) != 0; // Push message to the reply pipe. int rc = router_t::xsend (msg_); diff --git a/src/req.cpp b/src/req.cpp index ca9718df..8db98d03 100644 --- a/src/req.cpp +++ b/src/req.cpp @@ -126,7 +126,7 @@ int zmq::req_t::xsend (msg_t *msg_) } } - bool more = msg_->flags () & msg_t::more ? true : false; + bool more = (msg_->flags () & msg_t::more) != 0; int rc = dealer_t::xsend (msg_); if (rc != 0) From e19823d83a41ff051ccb4652cce9762e06d4aec0 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Thu, 17 May 2018 15:04:10 +0200 Subject: [PATCH 6/6] Problem: redundant else Solution: remove redundant else --- src/req.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/req.cpp b/src/req.cpp index 8db98d03..969ee46d 100644 --- a/src/req.cpp +++ b/src/req.cpp @@ -299,7 +299,8 @@ int zmq::req_session_t::push_msg (msg_t *msg_) if (msg_->size () == sizeof (uint32_t)) { state = request_id; return session_base_t::push_msg (msg_); - } else if (msg_->size () == 0) { + } + if (msg_->size () == 0) { state = body; return session_base_t::push_msg (msg_); }