]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: Fix pointer to integer casts on Windows
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Thu, 10 Oct 2019 13:30:48 +0000 (16:30 +0300)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Mon, 22 Jun 2020 09:03:49 +0000 (09:03 +0000)
'long' will be 32b on Windows, even on x64 targets. For this reason,
we can't use "long" when casting a pointer.

We'll use uintptr_t instead.

Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
src/common/buffer.cc
src/include/buffer.h
src/include/err.h

index 331ad890e555297357ab116ca554300d205de9c3..1751f8e8058cc31e7f8e7394d33efc5615a908f8 100644 (file)
@@ -193,7 +193,7 @@ static ceph::spinlock debug_lock;
     raw_hack_aligned(unsigned l, unsigned _align) : raw(l) {
       align = _align;
       realdata = new char[len+align-1];
-      unsigned off = ((unsigned)realdata) & (align-1);
+      unsigned off = ((uintptr_t)realdata) & (align-1);
       if (off)
        data = realdata + align - off;
       else
@@ -201,7 +201,7 @@ static ceph::spinlock debug_lock;
       //cout << "hack aligned " << (unsigned)data
       //<< " in raw " << (unsigned)realdata
       //<< " off " << off << std::endl;
-      ceph_assert(((unsigned)data & (align-1)) == 0);
+      ceph_assert(((uintptr_t)data & (align-1)) == 0);
     }
     ~raw_hack_aligned() {
       delete[] realdata;
index 91caab2accb29934a7c4282e2a7141ce0d945773..0c7a6dd8e0a61cfc90f8aac4392933226e4c5e21 100644 (file)
@@ -267,7 +267,7 @@ struct error_code;
 
     // misc
     bool is_aligned(unsigned align) const {
-      return ((long)c_str() & (align-1)) == 0;
+      return ((uintptr_t)c_str() & (align-1)) == 0;
     }
     bool is_page_aligned() const { return is_aligned(CEPH_PAGE_SIZE); }
     bool is_n_align_sized(unsigned align) const
index ba4b32aec38ced8ae1b7f802b082b26f5c71133c..2c63b69909bbf6d1ae779eb366f5c498e66bc200 100644 (file)
@@ -8,6 +8,7 @@
 #define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO)
 
 #include <errno.h>
+#include <stdint.h>
 
 /* this generates a warning in c++; caller can do the cast manually
 static inline void *ERR_PTR(long error)
@@ -18,12 +19,12 @@ static inline void *ERR_PTR(long error)
 
 static inline long PTR_ERR(const void *ptr)
 {
-  return (long) ptr;
+  return (uintptr_t) ptr;
 }
 
 static inline long IS_ERR(const void *ptr)
 {
-  return IS_ERR_VALUE((unsigned long)ptr);
+  return IS_ERR_VALUE((uintptr_t)ptr);
 }
 
 #endif