Any comments or suggestions?

**********

$ git diff misc.h misc.cpp
diff --git a/misc.cpp b/misc.cpp
old mode 100644
new mode 100755
diff --git a/misc.h b/misc.h
old mode 100644
new mode 100755
index b6a1b86..97cb77e
--- a/misc.h
+++ b/misc.h
@@ -5,6 +5,11 @@
 #include "smartptr.h"
 #include <string.h>            // for memcpy and memmove
 
+#ifndef NDEBUG
+# include <cassert>
+# include <limits>      // numeric_limits<T> for casts/asserts
+#endif
+
 #ifdef _MSC_VER
        #if _MSC_VER >= 1400
                // VC2005 workaround: disable declarations that conflict 
with wi
@@ -277,7 +282,7 @@ unsigned int BitPrecision(const T &value)
 inline unsigned int TrailingZeros(word32 v)
 {
 #if defined(__GNUC__) && CRYPTOPP_GCC_VERSION >= 30400
-       return __builtin_ctz(v);
+       return static_cast<unsigned int>(__builtin_ctz(v));
 #elif defined(_MSC_VER) && _MSC_VER >= 1400
        unsigned long result;
        _BitScanForward(&result, v);
@@ -296,7 +301,7 @@ inline unsigned int TrailingZeros(word32 v)
 inline unsigned int TrailingZeros(word64 v)
 {
 #if defined(__GNUC__) && CRYPTOPP_GCC_VERSION >= 30400
-       return __builtin_ctzll(v);
+       return static_cast<unsigned int>(__builtin_ctzll(v));
 #elif defined(_MSC_VER) && _MSC_VER >= 1400 && (defined(_M_X64) || 
defined(_M_I
        unsigned long result;
        _BitScanForward64(&result, v);
@@ -425,6 +430,16 @@ inline bool NativeByteOrderIs(ByteOrder order)
        return order == GetNativeByteOrder();
 }
 
+template<bool B, class T, class F>
+struct conditional { typedef T type; };
+template<class T, class F>
+struct conditional<false, T, F> { typedef F type; };
+
+template <typename T>
+struct signedness {
+       typedef typename conditional<T(-1)<T(0),signed,unsigned>::type type;
+};
+
 template <class T>
 std::string IntToString(T a, unsigned int base = 10)
 {
@@ -436,10 +451,13 @@ std::string IntToString(T a, unsigned int base = 10)
                negate = true;
                a = 0-a;        // VC .NET does not like -a
        }
+
+       // Extract {signed|unsigned} type for T to achieve a clean compile
+       const typename signedness<T>::type b = static_cast<typename 
signedness<T
        std::string result;
        while (a > 0)
        {
-               T digit = a % base;
+               T digit = a % b;
                result = char((digit < 10 ? '0' : ('a' - 10)) + digit) + 
result;
                a /= base;
        }
@@ -464,16 +482,22 @@ CRYPTOPP_DLL void CRYPTOPP_API CallNewHandler();
 
 inline void IncrementCounterByOne(byte *inout, unsigned int s)
 {
-       for (int i=s-1, carry=1; i>=0 && carry; i--)
+       assert(s >= 1);
+       assert(s <= static_cast<unsigned 
int>(std::numeric_limits<int>::max()));
+
+       for (int i=static_cast<int>(s)-1, carry=1; i>=0 && carry; i--)
                carry = !++inout[i];
 }
 
 inline void IncrementCounterByOne(byte *output, const byte *input, 
unsigned int
 {
+       assert(s >= 1);
+       assert(s <= static_cast<unsigned 
int>(std::numeric_limits<int>::max()));
+
        int i, carry;
-       for (i=s-1, carry=1; i>=0 && carry; i--)
+       for (i=static_cast<int>(s)-1, carry=1; i>=0 && carry; i--)
                carry = ((output[i] = input[i]+1) == 0);
-       memcpy_s(output, s, input, i+1);
+       memcpy_s(output, s, input, static_cast<unsigned int>(i)+1);
 }
 
 template <class T>
riemann::cryptopp-master$ 

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to