summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-12-04 21:42:23 -0500
committerJeffrey Walton <noloader@gmail.com>2018-12-04 21:42:23 -0500
commit7832ae373364361f966b4c5b02b117fe6b83fc11 (patch)
treebc4f1791f554b6b207b62c60e4f0913ab7acc004
parenta1c89661bcd34dc2d46bdf057704843d29461426 (diff)
downloadcryptopp-git-7832ae373364361f966b4c5b02b117fe6b83fc11.tar.gz
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.
-rw-r--r--misc.h34
1 files 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 <tt>ptr</tt> is aligned on at least <tt>alignment</tt> 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 <tt>ptr</tt> is aligned on at least <tt>alignment</tt>
+/// 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<size_t>(ptr), alignment) == 0 : reinterpret_cast<size_t>(ptr) % alignment == 0);
+ const uintptr_t x = reinterpret_cast<uintptr_t>(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 <tt>ptr</tt> is aligned to at least <tt>T</tt> boundary, false otherwise
-/// \details Internally the function calls IsAlignedOn with a second parameter of GetAlignmentOf<T>
+/// \returns true if <tt>ptr</tt> is aligned to at least <tt>T</tt>
+/// boundary, false otherwise
+/// \details Internally the function calls IsAlignedOn with a second
+/// parameter of GetAlignmentOf<T>.
template <class T>
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();