aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaspar Schleiser <kaspar@schleiser.de>2018-03-23 22:10:41 +0100
committerKaspar Schleiser <kaspar@schleiser.de>2018-03-23 22:10:41 +0100
commit6afc222e0b4373b04fde5b94742a224a72c57cca (patch)
treefaa98238a00a05033b2a139c47187c57ca49cce6
parent3d8c1e859e170cdca1a66bc4124fccba9a47c853 (diff)
downloadcn-cbor-6afc222e0b4373b04fde5b94742a224a72c57cca.tar.gz
fixup! implement alignment-safe ntoh16p() && ntoh32p()
-rw-r--r--src/cn-cbor.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/cn-cbor.c b/src/cn-cbor.c
index 400de5f..b5759e6 100644
--- a/src/cn-cbor.c
+++ b/src/cn-cbor.c
@@ -49,8 +49,12 @@ static double decode_half(int half) {
}
#endif /* CBOR_NO_FLOAT */
-/* Fix these if you can't do non-aligned reads */
#define ntoh8p(p) (*(unsigned char*)(p))
+
+#ifndef CBOR_ALIGN_MEMREADS
+#define ntoh16p(p) (ntohs(*(unsigned short*)(p)))
+#define ntoh32p(p) (ntohl(*(unsigned long*)(p)))
+#else
static uint16_t ntoh16p(unsigned char *p) {
uint16_t tmp;
memcpy(&tmp, p, sizeof(tmp));
@@ -62,6 +66,7 @@ static uint32_t ntoh32p(unsigned char *p) {
memcpy(&tmp, p, sizeof(tmp));
return ntohl(tmp);
}
+#endif
static uint64_t ntoh64p(unsigned char *p) {
uint64_t ret = ntoh32p(p);