From a4c817e73617e96bd1371a5addd6c49879b091cc Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Mon, 28 May 2018 18:45:41 +0200 Subject: [PATCH] Problem: magic number "2" in socket_base.cpp Solution: calculate from field sizes --- src/socket_base.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/socket_base.cpp b/src/socket_base.cpp index 8e4a8d26..5e951973 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -1731,14 +1731,14 @@ void zmq::socket_base_t::monitor_event (int event_, if (_monitor_socket) { // Send event in first frame + const uint16_t event = static_cast (event_); + const uint32_t value = static_cast (value_); zmq_msg_t msg; - zmq_msg_init_size (&msg, 6); + zmq_msg_init_size (&msg, sizeof (event) + sizeof (value)); uint8_t *data = static_cast (zmq_msg_data (&msg)); // Avoid dereferencing uint32_t on unaligned address - uint16_t event = static_cast (event_); - uint32_t value = static_cast (value_); memcpy (data + 0, &event, sizeof (event)); - memcpy (data + 2, &value, sizeof (value)); + memcpy (data + sizeof (event), &value, sizeof (value)); zmq_sendmsg (_monitor_socket, &msg, ZMQ_SNDMORE); // Send address in second frame