From 7832ae373364361f966b4c5b02b117fe6b83fc11 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Tue, 4 Dec 2018 21:42:23 -0500 Subject: [PATCH] Switch to uintptr_t for IsAlignedOn I thought this might be part of the problem for https://groups.google.com/d/msg/cryptopp-users/sHCHSjM7scY/PkcSbIo-DQAJ but it did not help. However, the uintptr_t is the proper cast here. --- misc.h | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/misc.h b/misc.h index 0e420f9a..29b07209 100644 --- a/misc.h +++ b/misc.h @@ -1077,19 +1077,24 @@ inline unsigned int GetAlignmentOf() /// \brief Determines whether ptr is aligned to a minimum value /// \param ptr the pointer being checked for alignment /// \param alignment the alignment value to test the pointer against -/// \returns true if ptr is aligned on at least alignment boundary, false otherwise -/// \details Internally the function tests whether alignment is 1. If so, the function returns true. -/// If not, then the function effectively performs a modular reduction and returns true if the residue is 0 +/// \returns true if ptr is aligned on at least alignment +/// boundary, false otherwise +/// \details Internally the function tests whether alignment is 1. If so, +/// the function returns true. If not, then the function effectively +/// performs a modular reduction and returns true if the residue is 0. inline bool IsAlignedOn(const void *ptr, unsigned int alignment) { - return alignment==1 || (IsPowerOf2(alignment) ? ModPowerOf2(reinterpret_cast(ptr), alignment) == 0 : reinterpret_cast(ptr) % alignment == 0); + const uintptr_t x = reinterpret_cast(ptr); + return alignment==1 || (IsPowerOf2(alignment) ? ModPowerOf2(x, alignment) == 0 : x % alignment == 0); } /// \brief Determines whether ptr is minimally aligned /// \tparam T class or type /// \param ptr the pointer to check for alignment -/// \returns true if ptr is aligned to at least T boundary, false otherwise -/// \details Internally the function calls IsAlignedOn with a second parameter of GetAlignmentOf +/// \returns true if ptr is aligned to at least T +/// boundary, false otherwise +/// \details Internally the function calls IsAlignedOn with a second +/// parameter of GetAlignmentOf. template inline bool IsAligned(const void *ptr) { @@ -1105,14 +1110,15 @@ inline bool IsAligned(const void *ptr) #endif /// \brief Returns NativeByteOrder as an enumerated ByteOrder value -/// \returns LittleEndian if the native byte order is little-endian, and BigEndian if the -/// native byte order is big-endian -/// \details NativeByteOrder is a typedef depending on the platform. If CRYPTOPP_LITTLE_ENDIAN is -/// set in config.h, then GetNativeByteOrder returns LittleEndian. If -/// (CRYPTOPP_BIG_ENDIAN) is set, then GetNativeByteOrder returns BigEndian. -/// \note There are other byte orders besides little- and big-endian, and they include bi-endian -/// and PDP-endian. If a system is neither little-endian nor big-endian, then a compile time -/// error occurs. +/// \returns LittleEndian if the native byte order is little-endian, +/// and BigEndian if the native byte order is big-endian +/// \details NativeByteOrder is a typedef depending on the platform. +/// If CRYPTOPP_LITTLE_ENDIAN is set in config.h, then +/// GetNativeByteOrder returns LittleEndian. If CRYPTOPP_BIG_ENDIAN +/// is set, then GetNativeByteOrder returns BigEndian. +/// \note There are other byte orders besides little- and big-endian, +/// and they include bi-endian and PDP-endian. If a system is neither +/// little-endian nor big-endian, then a compile time error occurs. inline ByteOrder GetNativeByteOrder() { return NativeByteOrder::ToEnum();