summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Wragg <david@rabbitmq.com>2011-08-18 17:17:51 +0100
committerDavid Wragg <david@rabbitmq.com>2011-08-18 17:17:51 +0100
commit9ad5ead9668d078d6c5c2ab9a24a0d31d60f79d0 (patch)
tree3a9511cfb940f9657f862ea6b314a4da384987d3
parentfed4aebe364bb832de098c45473d1304644cb757 (diff)
downloadrabbitmq-c-github-ask-bug24349.tar.gz
Comment magical memcpysbug24349
-rw-r--r--librabbitmq/amqp_private.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/librabbitmq/amqp_private.h b/librabbitmq/amqp_private.h
index dff12db..6c15383 100644
--- a/librabbitmq/amqp_private.h
+++ b/librabbitmq/amqp_private.h
@@ -146,12 +146,16 @@ static inline void *amqp_offset(void *data, size_t offset)
static inline void amqp_e##bits(void *data, size_t offset, \
uint##bits##_t val) \
{ \
- uint##bits##_t res = htonx(val); \
+ /* The AMQP data might be unaligned. So we encode and then copy the \
+ result into place. */ \
+ uint##bits##_t res = htonx(val); \
memcpy(amqp_offset(data, offset), &res, bits/8); \
} \
\
static inline uint##bits##_t amqp_d##bits(void *data, size_t offset) \
-{ \
+{ \
+ /* The AMQP data might be unaligned. So we copy the source value \
+ into a variable and then decode it. */ \
uint##bits##_t val; \
memcpy(&val, amqp_offset(data, offset), bits/8); \
return ntohx(val); \