Skip to content

Commit 0c0f3ae

Browse files
committed
Fixed misaligned structure cast
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.
1 parent ee47ae4 commit 0c0f3ae

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

zmq.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,11 @@ namespace zmq
492492
if (rc == -1 && zmq_errno() == ETERM)
493493
break;
494494
assert (rc != -1);
495-
zmq_event_t* event = static_cast<zmq_event_t*>(zmq_msg_data (&eventMsg));
495+
const char* data = static_cast<const char*>(zmq_msg_data(&eventMsg));
496+
zmq_event_t msgEvent;
497+
msgEvent.event = *(uint16_t*)data; data += sizeof(uint16_t);
498+
msgEvent.value = *(int32_t*)data;
499+
zmq_event_t* event = &msgEvent;
496500

497501
#ifdef ZMQ_NEW_MONITOR_EVENT_LAYOUT
498502
zmq_msg_t addrMsg;

0 commit comments

Comments
 (0)