From 264018e8ec9ee3fdd5fe7d32f91dd91f8dffc6bb Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Thu, 30 Jul 2015 09:14:43 -0400 Subject: [PATCH] Suppressed "sign comparison" warning under GCC and Clang --- misc.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/misc.h b/misc.h index 02a289fd..06cc3c62 100644 --- a/misc.h +++ b/misc.h @@ -59,7 +59,6 @@ # pragma GCC diagnostic ignored "-Wunused-value" # pragma GCC diagnostic ignored "-Wunused-variable" # pragma GCC diagnostic ignored "-Wunused-parameter" -# pragma GCC diagnostic ignored "-Wtype-limit" #endif NAMESPACE_BEGIN(CryptoPP) @@ -198,6 +197,9 @@ const T & Singleton::Ref(CRYPTOPP_NOINLINE_DOTDOTDOT) const #if (!__STDC_WANT_SECURE_LIB__ && !defined(_MEMORY_S_DEFINED)) inline void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count) { + // NULL pointers to memcpy is undefined behavior + CRYPTOPP_ASSERT(dest); CRYPTOPP_ASSERT(src); + if (count > sizeInBytes) throw InvalidArgument("memcpy_s: buffer overflow"); @@ -209,6 +211,9 @@ inline void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t cou inline void memmove_s(void *dest, size_t sizeInBytes, const void *src, size_t count) { + // NULL pointers to memmove is undefined behavior + CRYPTOPP_ASSERT(dest); CRYPTOPP_ASSERT(src); + if (count > sizeInBytes) throw InvalidArgument("memmove_s: buffer overflow"); @@ -365,6 +370,11 @@ inline T Crop(T value, size_t size) return value; } +#if GCC_DIAGNOSTIC_AWARE +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wsign-compare" +#endif + template inline bool SafeConvert(T1 from, T2 &to) { @@ -374,6 +384,10 @@ inline bool SafeConvert(T1 from, T2 &to) return true; } +#if GCC_DIAGNOSTIC_AWARE +# pragma GCC diagnostic pop +#endif + inline size_t BitsToBytes(size_t bitCount) { return ((bitCount+7)/(8));