diff --git a/misc.h b/misc.h index 0a2b681e..7e61605b 100644 --- a/misc.h +++ b/misc.h @@ -1,10 +1,14 @@ #ifndef CRYPTOPP_MISC_H #define CRYPTOPP_MISC_H +#include // for size_t when -stdlib=libc++ + #include "cryptlib.h" #include "smartptr.h" #include "trap.h" -#include // for memcpy and memmove + +#include // for memcpy and memmove +#include // for size_t when -stdlib=libc++ #include // for std::streamsize #include // for std::numeric_limits @@ -370,8 +374,8 @@ inline bool SafeConvert(T1 from, T2 &to) return true; } -// MSVC see this as a duplicate specialization -#ifndef _MSC_VER +// MSVC see this as a duplicate specialization. Apple can't find std::streamsize. +#if !defined(_MSC_VER) && !defined(__APPLE__) // files.cpp, line 235 template<> inline bool SafeConvert(size_t from, std::streamsize &to) @@ -383,6 +387,19 @@ inline bool SafeConvert(size_t from, std::streamsize &to } #endif +// Apple can't find std::streamsize +#if defined(__APPLE__) +// files.cpp, line 235 +template<> +inline bool SafeConvert(unsigned long from, long &to) +{ + to = (long)from; + if(from > static_cast(std::numeric_limits::max())) + return false; + return true; +} +#endif + // files.cpp, line 366 template<> inline bool SafeConvert(long long unsigned int from, long int &to) @@ -681,6 +698,11 @@ template<> inline void SecureWipeBuffer(word64 *buf, size_t n) #endif // #if (_MSC_VER >= 1400 || defined(__GNUC__)) && (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86) +#if GCC_DIAGNOSTIC_AWARE +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wcast-align" +#endif + template inline void SecureWipeArray(T *buf, size_t n) { @@ -694,6 +716,10 @@ inline void SecureWipeArray(T *buf, size_t n) SecureWipeBuffer((byte *)buf, n * sizeof(T)); } +#if GCC_DIAGNOSTIC_AWARE +# pragma GCC diagnostic pop +#endif + // this function uses wcstombs(), which assumes that setlocale() has been called static inline std::string StringNarrow(const wchar_t *str, bool throwOnError = true) {