From 45923c08b00ccdfd888caf6d2b555a137c563988 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 18 Oct 2017 16:13:24 +0000 Subject: Better packing / unpacking code Godbolted for x86_64 with gcc and clang. --- src/libstddjb/uint16_pack.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/libstddjb/uint16_pack.c') diff --git a/src/libstddjb/uint16_pack.c b/src/libstddjb/uint16_pack.c index de0a09b..e7ffe24 100644 --- a/src/libstddjb/uint16_pack.c +++ b/src/libstddjb/uint16_pack.c @@ -1,10 +1,11 @@ /* ISC license. */ +#include +#include #include -#include void uint16_pack (char *s, uint16_t u) { - ((unsigned char *)s)[0] = T8(u) ; u >>= 8 ; - ((unsigned char *)s)[1] = T8(u) ; + u = uint16_little(u) ; + memcpy(s, &u, sizeof(uint16_t)) ; } -- cgit v1.2.3