From 3f30574cedd9df05c747191490db23c25e0c00e6 Mon Sep 17 00:00:00 2001 From: weidai Date: Fri, 21 Nov 2008 03:05:32 +0000 Subject: [PATCH] fixes for GCC 4.3.2 (reports from Chris Morgan and DiegoT) --- integer.cpp | 8 ++++---- misc.h | 12 +++++++++++- modes.h | 6 +++--- secblock.h | 4 ++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/integer.cpp b/integer.cpp index 56dab61a..e5aa95e8 100644 --- a/integer.cpp +++ b/integer.cpp @@ -547,8 +547,8 @@ int Baseline_Add(size_t N, word *C, const word *A, const word *B) AS2( mov %0, 0) AS2( adc %0, %0) ".att_syntax;" - : "=&r" (result) - : "c" (N), "r" (C+N), "r" (A+N), "r" (B+N) + : "=&r" (result), "+c" (N) + : "r" (C+N), "r" (A+N), "r" (B+N) : "memory", "cc" ); return (int)result; @@ -579,8 +579,8 @@ int Baseline_Sub(size_t N, word *C, const word *A, const word *B) AS2( mov %0, 0) AS2( adc %0, %0) ".att_syntax;" - : "=&r" (result) - : "c" (N), "r" (C+N), "r" (A+N), "r" (B+N) + : "=&r" (result), "+c" (N) + : "r" (C+N), "r" (A+N), "r" (B+N) : "memory", "cc" ); return (int)result; diff --git a/misc.h b/misc.h index 341476cf..5c3a6d19 100644 --- a/misc.h +++ b/misc.h @@ -166,6 +166,16 @@ inline void memmove_s(void *dest, size_t sizeInBytes, const void *src, size_t co } #endif +inline void * memset_z(void *ptr, int value, size_t num) +{ +// avoid extranous warning on GCC 4.3.2 Ubuntu 8.10 +#if CRYPTOPP_GCC_VERSION >= 30001 + if (__builtin_constant_p(num) && num==0) + return ptr; +#endif + return memset(ptr, value, num); +} + // can't use std::min or std::max in MSVC60 or Cygwin 1.1.0 template inline const T& STDMIN(const T& a, const T& b) { @@ -797,7 +807,7 @@ inline void GetUserKey(ByteOrder order, T *out, size_t outlen, const byte *in, s const size_t U = sizeof(T); assert(inlen <= outlen*U); memcpy(out, in, inlen); - memset((byte *)out+inlen, 0, outlen*U-inlen); + memset_z((byte *)out+inlen, 0, outlen*U-inlen); ConditionalByteReverse(order, out, out, RoundUpToMultipleOf(inlen, U)); } diff --git a/modes.h b/modes.h index d6822ff9..1bf36aef 100644 --- a/modes.h +++ b/modes.h @@ -308,12 +308,12 @@ class CipherModeFinalTemplate_ExternalCipher : public BASE public: CipherModeFinalTemplate_ExternalCipher() {} CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher) - {SetCipher(cipher);} + {this->SetCipher(cipher);} CipherModeFinalTemplate_ExternalCipher(BlockCipher &cipher, const byte *iv, int feedbackSize = 0) - {SetCipherWithIV(cipher, iv, feedbackSize);} + {this->SetCipherWithIV(cipher, iv, feedbackSize);} std::string AlgorithmName() const - {return m_cipher->AlgorithmName() + "/" + BASE::StaticAlgorithmName();} + {return this->m_cipher->AlgorithmName() + "/" + BASE::StaticAlgorithmName();} }; CRYPTOPP_DLL_TEMPLATE_CLASS CFB_CipherTemplate >; diff --git a/secblock.h b/secblock.h index aecd4d46..3d309e6a 100644 --- a/secblock.h +++ b/secblock.h @@ -130,7 +130,7 @@ public: void deallocate(void *p, size_type n) { - memset(p, 0, n*sizeof(T)); + memset_z(p, 0, n*sizeof(T)); if (T_Align16 && n*sizeof(T) >= 16) { @@ -288,7 +288,7 @@ public: { m_ptr = m_alloc.allocate(len, NULL); if (t == NULL) - memset(m_ptr, 0, len*sizeof(T)); + memset_z(m_ptr, 0, len*sizeof(T)); else memcpy(m_ptr, t, len*sizeof(T)); }