From ad1338cbe252287aa6cbdbbb4e8d129b461f51f2 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Thu, 10 Oct 2019 16:30:48 +0300 Subject: [PATCH] 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 --- src/common/buffer.cc | 4 ++-- src/include/buffer.h | 2 +- src/include/err.h | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 331ad890e555..1751f8e8058c 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 91caab2accb2..0c7a6dd8e0a6 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 ba4b32aec38c..2c63b69909bb 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 -- 2.47.3