From 5790163abc936d2630c70d294dc5a617d7d6efa7 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Tue, 13 Sep 2016 22:28:03 -0400 Subject: [PATCH] Use __BIGGEST_ALIGNMENT__ only if its smaller than sizeof\(T\) --- misc.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/misc.h b/misc.h index b44c8fe3..23ef0999 100644 --- a/misc.h +++ b/misc.h @@ -875,7 +875,8 @@ inline T1 RoundUpToMultipleOf(const T1 &n, const T2 &m) //! \details Internally the function calls C++11's alignof if available. If not available, //! then the function uses compiler specific extensions such as __alignof and //! _alignof_. If an extension is not available, then the function uses -//! __BIGGEST_ALIGNMENT__. sizeof(T) is used if the others are not available. +//! __BIGGEST_ALIGNMENT__ if __BIGGEST_ALIGNMENT__ is smaller than sizeof(T). +//! sizeof(T) is used if all others are not available. //! In all cases, if CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS is defined, then the //! function returns 1. template @@ -893,11 +894,14 @@ inline unsigned int GetAlignmentOf(T *dummy=NULL) // VC60 workaround return __alignof(T); #elif defined(__GNUC__) return __alignof__(T); -#elif __BIGGEST_ALIGNMENT__ - return __BIGGEST_ALIGNMENT__; #elif CRYPTOPP_BOOL_SLOW_WORD64 return UnsignedMin(4U, sizeof(T)); #else +# if __BIGGEST_ALIGNMENT__ + if (__BIGGEST_ALIGNMENT__ < sizeof(T)) + return __BIGGEST_ALIGNMENT__; + else +# endif return sizeof(T); #endif }