mirror of
https://github.com/zeromq/cppzmq.git
synced 2025-01-06 00:31:14 +01:00
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.
This commit is contained in:
parent
ee47ae4cdd
commit
0c0f3ae451
6
zmq.hpp
6
zmq.hpp
@ -492,7 +492,11 @@ namespace zmq
|
|||||||
if (rc == -1 && zmq_errno() == ETERM)
|
if (rc == -1 && zmq_errno() == ETERM)
|
||||||
break;
|
break;
|
||||||
assert (rc != -1);
|
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
|
#ifdef ZMQ_NEW_MONITOR_EVENT_LAYOUT
|
||||||
zmq_msg_t addrMsg;
|
zmq_msg_t addrMsg;
|
||||||
|
Loading…
Reference in New Issue
Block a user