From: Ulrich Weigand Date: Thu, 12 Sep 2019 13:46:06 +0000 (+0200) Subject: cmake: Fix unaligned check on big-endian systems X-Git-Tag: v15.1.0~1549^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5a189bdd416c5afb61b66871231e6dbde288a96a;p=ceph.git cmake: Fix unaligned check on big-endian systems On big-endian systems, ntohl is a no-op, so "good" never does any conversion. Fix this by keeping the test constants in big-endian (network) order and using ntohl to convert them to native (host) byte order. Signed-off-by: Ulrich Weigand --- diff --git a/cmake/modules/CephChecks.cmake b/cmake/modules/CephChecks.cmake index f6dd41cf105..2bc850456ad 100644 --- a/cmake/modules/CephChecks.cmake +++ b/cmake/modules/CephChecks.cmake @@ -104,23 +104,18 @@ uint32_t load(char* p, size_t offset) return *reinterpret_cast(p + offset); } -bool good(uint32_t lhs, uint32_t small_endian) +bool good(uint32_t lhs, uint32_t big_endian) { - uint32_t rhs; - if (ntohl(0xdeadbeaf) == 0xdeadbeaf) { - return lhs == ntohl(small_endian); - } else { - return lhs == small_endian; - } + return lhs == ntohl(big_endian); } int main(int argc, char **argv) { char a1[] = \"ABCDEFG\"; - uint32_t a2[] = {0x44434241, - 0x45444342, - 0x46454443, - 0x47464544}; + uint32_t a2[] = {0x41424344, + 0x42434445, + 0x43444546, + 0x44454647}; for (size_t i = 0; i < std::size(a2); i++) { if (!good(load(a1, i), a2[i])) { return 1;