From 9ad5ead9668d078d6c5c2ab9a24a0d31d60f79d0 Mon Sep 17 00:00:00 2001 From: David Wragg Date: Thu, 18 Aug 2011 17:17:51 +0100 Subject: Comment magical memcpys --- librabbitmq/amqp_private.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'librabbitmq') 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); \ -- cgit v1.2.1