Fix loop index var types, fixing many minor sign comparison warnings
[novacoin.git] / src / base58.h
index 985b044..592756f 100644 (file)
@@ -1,4 +1,5 @@
 // Copyright (c) 2009-2010 Satoshi Nakamoto
+// Copyright (c) 2011 The Bitcoin Developers
 // Distributed under the MIT/X11 software license, see the accompanying
 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
 
@@ -173,14 +174,16 @@ protected:
 
     ~CBase58Data()
     {
-        memset(&vchData[0], 0, vchData.size());
+        if (!vchData.empty())
+            memset(&vchData[0], 0, vchData.size());
     }
 
     void SetData(int nVersionIn, const void* pdata, size_t nSize)
     {
         nVersion = nVersionIn;
         vchData.resize(nSize);
-        memcpy(&vchData[0], pdata, nSize);
+        if (!vchData.empty())
+            memcpy(&vchData[0], pdata, nSize);
     }
 
     void SetData(int nVersionIn, const unsigned char *pbegin, const unsigned char *pend)
@@ -201,7 +204,8 @@ public:
         }
         nVersion = vchTemp[0];
         vchData.resize(vchTemp.size() - 1);
-        memcpy(&vchData[0], &vchTemp[1], vchData.size());
+        if (!vchData.empty())
+            memcpy(&vchData[0], &vchTemp[1], vchData.size());
         memset(&vchTemp[0], 0, vchTemp.size());
         return true;
     }
@@ -221,7 +225,7 @@ public:
     int CompareTo(const CBase58Data& b58) const
     {
         if (nVersion < b58.nVersion) return -1;
-        if (nVersion < b58.nVersion) return  1;
+        if (nVersion > b58.nVersion) return  1;
         if (vchData < b58.vchData)   return -1;
         if (vchData > b58.vchData)   return  1;
         return 0;
@@ -241,6 +245,7 @@ public:
     bool SetHash160(const uint160& hash160)
     {
         SetData(fTestNet ? 111 : 0, &hash160, 20);
+        return true;
     }
 
     bool SetPubKey(const std::vector<unsigned char>& vchPubKey)