Skip to content

Commit

Permalink
Fixed misaligned structure cast
Browse files Browse the repository at this point in the history
zmq_event_t is often padded (due to a uint16_t as its first member), and thus you cannot re-interpret bytewise packed message buffers as zmq_event_t, it must be read manually. This was resulting in the value always being garbage, which is troublesome if you wish to inspect a SOCKET, for example.
  • Loading branch information
justinboswell committed Aug 6, 2014
1 parent ee47ae4 commit 0c0f3ae
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,11 @@ namespace zmq
if (rc == -1 && zmq_errno() == ETERM)
break;
assert (rc != -1);
zmq_event_t* event = static_cast<zmq_event_t*>(zmq_msg_data (&eventMsg));
const char* data = static_cast<const char*>(zmq_msg_data(&eventMsg));
zmq_event_t msgEvent;
msgEvent.event = *(uint16_t*)data; data += sizeof(uint16_t);
msgEvent.value = *(int32_t*)data;
zmq_event_t* event = &msgEvent;

#ifdef ZMQ_NEW_MONITOR_EVENT_LAYOUT
zmq_msg_t addrMsg;
Expand Down

0 comments on commit 0c0f3ae

Please sign in to comment.