Use memcpy instead of assuming option values are aligned

Otherwise, it's undefined behavior. ubsan catches alignment issues in
the libzmq test suite without this.
This commit is contained in:
Brian Silverman
2016-02-06 22:20:42 -05:00
parent ffe4a1c615
commit 273b54715e
5 changed files with 10 additions and 5 deletions

View File

@@ -97,7 +97,8 @@ int zmq::router_t::xsetsockopt (int option_, const void *optval_,
size_t optvallen_)
{
bool is_int = (optvallen_ == sizeof (int));
int value = is_int? *((int *) optval_): 0;
int value = 0;
if (is_int) memcpy(&value, optval_, sizeof (int));
switch (option_) {
case ZMQ_CONNECT_RID: