From: Lucian Petrut Date: Thu, 10 Oct 2019 13:30:48 +0000 (+0300) Subject: common: Fix pointer to integer casts on Windows X-Git-Tag: wip-pdonnell-testing-20200918.022351~697^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ad1338cbe252287aa6cbdbbb4e8d129b461f51f2;p=ceph-ci.git common: Fix pointer to integer casts on Windows '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 --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 331ad890e55..1751f8e8058 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -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; diff --git a/src/include/buffer.h b/src/include/buffer.h index 91caab2accb..0c7a6dd8e0a 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -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 diff --git a/src/include/err.h b/src/include/err.h index ba4b32aec38..2c63b69909b 100644 --- a/src/include/err.h +++ b/src/include/err.h @@ -8,6 +8,7 @@ #define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO) #include +#include /* 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