]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: Fix unaligned check on big-endian systems 30362/head
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Thu, 12 Sep 2019 13:46:06 +0000 (15:46 +0200)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Thu, 12 Sep 2019 13:46:06 +0000 (15:46 +0200)
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 <ulrich.weigand@de.ibm.com>
cmake/modules/CephChecks.cmake

index f6dd41cf10555e01e4df056439f23b478bd05e8e..2bc850456ad58839ca8a08cc7b726ca0afb5637a 100644 (file)
@@ -104,23 +104,18 @@ uint32_t load(char* p, size_t offset)
   return *reinterpret_cast<uint32_t*>(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;