Skip to content

Commit a6ca65c

Browse files
authored
Merge pull request #401 from gummif/gfa/msg-ub
Problem: UB in message_t constructor
2 parents 3746e5c + 1793a5b commit a6ca65c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

zmq.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,12 @@ class message_t
365365
int rc = zmq_msg_init_size(&msg, size_);
366366
if (rc != 0)
367367
throw error_t();
368-
memcpy(data(), data_, size_);
368+
if (size_)
369+
{
370+
// this constructor allows (nullptr, 0),
371+
// memcpy with a null pointer is UB
372+
memcpy(data(), data_, size_);
373+
}
369374
}
370375

371376
message_t(void *data_, size_t size_, free_fn *ffn_, void *hint_ = ZMQ_NULLPTR)

0 commit comments

Comments
 (0)