Blob Blame History Raw
From 822739a9f5163f6836a05e694faaa7b88d74f39c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
Date: Tue, 9 Jan 2018 17:01:04 +0100
Subject: [PATCH] Fix machine portability issues, fixes tests on non-x86
 architectures

---
 lib/isc/tests/hash_test.c      | 15 +++++++++++++++
 lib/isc/unix/include/isc/int.h |  2 +-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/lib/isc/tests/hash_test.c b/lib/isc/tests/hash_test.c
index 0c287e83fa..d51b44fa26 100644
--- a/lib/isc/tests/hash_test.c
+++ b/lib/isc/tests/hash_test.c
@@ -1784,6 +1784,18 @@ ATF_TC_BODY(isc_hmacmd5, tc) {
 }
 #endif
 
+#ifdef WORDS_BIGENDIAN
+/* Source: https://stackoverflow.com/questions/2182002/convert-big-endian-to-little-endian-in-c-without-using-provided-func */
+static inline isc_uint64_t
+swap_uint64(isc_uint64_t val) {
+	val = ((val << 8) & 0xFF00FF00FF00FF00ULL ) |
+	      ((val >> 8) & 0x00FF00FF00FF00FFULL );
+	val = ((val << 16) & 0xFFFF0000FFFF0000ULL ) |
+	      ((val >> 16) & 0x0000FFFF0000FFFFULL );
+	return (val << 32) | (val >> 32);
+}
+#endif
+
 /* CRC64 Test */
 ATF_TC(isc_crc64);
 ATF_TC_HEAD(isc_crc64, tc) {
@@ -1839,6 +1851,9 @@ ATF_TC_BODY(isc_crc64, tc) {
 				       testcase->input_len);
 		}
 		isc_crc64_final(&crc);
+#ifdef WORDS_BIGENDIAN
+		crc = swap_uint64(crc);
+#endif
 		tohexstr((unsigned char *) &crc, sizeof(crc), str);
 		ATF_CHECK_STREQ(str, testcase->result);
 
diff --git a/lib/isc/unix/include/isc/int.h b/lib/isc/unix/include/isc/int.h
index 00fc048f65..706353eaca 100644
--- a/lib/isc/unix/include/isc/int.h
+++ b/lib/isc/unix/include/isc/int.h
@@ -13,7 +13,7 @@
 
 /*! \file */
 
-typedef char				isc_int8_t;
+typedef signed char			isc_int8_t;
 typedef unsigned char			isc_uint8_t;
 typedef short				isc_int16_t;
 typedef unsigned short			isc_uint16_t;
-- 
2.14.3