Use fixed size types for alerts;
authorCryptoManiac <balthazar@yandex.ru>
Sun, 10 Apr 2016 11:51:37 +0000 (14:51 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Sun, 10 Apr 2016 11:51:37 +0000 (14:51 +0300)
resolve some formatting warnings.

src/alert.cpp
src/alert.h
src/checkpoints.h
src/main.cpp
src/main.h
src/script.cpp

index 8719f78..380fece 100644 (file)
@@ -44,23 +44,23 @@ void CUnsignedAlert::SetNull()
 std::string CUnsignedAlert::ToString() const
 {
     std::string strSetCancel;
-    for(int n :  setCancel)
-        strSetCancel += strprintf("%d ", n);
+    for(int32_t n :  setCancel)
+        strSetCancel += strprintf("%" PRId32 " ", n);
     std::string strSetSubVer;
     for(std::string str :  setSubVer)
         strSetSubVer += "\"" + str + "\" ";
     return strprintf(
         "CAlert(\n"
-        "    nVersion     = %d\n"
+        "    nVersion     = %" PRId32 "\n"
         "    nRelayUntil  = %" PRId64 "\n"
         "    nExpiration  = %" PRId64 "\n"
-        "    nID          = %d\n"
-        "    nCancel      = %d\n"
+        "    nID          = %" PRId32 "\n"
+        "    nCancel      = %" PRId32 "\n"
         "    setCancel    = %s\n"
-        "    nMinVer      = %d\n"
-        "    nMaxVer      = %d\n"
+        "    nMinVer      = %" PRId32 "\n"
+        "    nMaxVer      = %" PRId32 "\n"
         "    setSubVer    = %s\n"
-        "    nPriority    = %d\n"
+        "    nPriority    = %" PRId32 "\n"
         "    strComment   = \"%s\"\n"
         "    strStatusBar = \"%s\"\n"
         ")\n",
@@ -203,13 +203,13 @@ bool CAlert::ProcessAlert()
             const CAlert& alert = (*mi).second;
             if (Cancels(alert))
             {
-                printf("cancelling alert %d\n", alert.nID);
+                printf("cancelling alert %" PRId32 "\n", alert.nID);
                 uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
                 mapAlerts.erase(mi++);
             }
             else if (!alert.IsInEffect())
             {
-                printf("expiring alert %d\n", alert.nID);
+                printf("expiring alert %" PRId32 "\n", alert.nID);
                 uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
                 mapAlerts.erase(mi++);
             }
@@ -223,7 +223,7 @@ bool CAlert::ProcessAlert()
             const CAlert& alert = item.second;
             if (alert.Cancels(*this))
             {
-                printf("alert already cancelled by %d\n", alert.nID);
+                printf("alert already cancelled by %" PRId32 "\n", alert.nID);
                 return false;
             }
         }
@@ -235,6 +235,6 @@ bool CAlert::ProcessAlert()
             uiInterface.NotifyAlertChanged(GetHash(), CT_NEW);
     }
 
-    printf("accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
+    printf("accepted alert %" PRId32 ", AppliesToMe()=%" PRId32 "\n", nID, AppliesToMe());
     return true;
 }
index c417842..ad7d381 100644 (file)
@@ -23,16 +23,16 @@ class CNode;
 class CUnsignedAlert
 {
 public:
-    int nVersion;
+    int32_t nVersion;
     int64_t nRelayUntil;      // when newer nodes stop relaying to newer nodes
     int64_t nExpiration;
-    int nID;
-    int nCancel;
-    std::set<int> setCancel;
-    int nMinVer;            // lowest version inclusive
-    int nMaxVer;            // highest version inclusive
+    int32_t nID;
+    int32_t nCancel;
+    std::set<int32_t> setCancel;
+    int32_t nMinVer;            // lowest version inclusive
+    int32_t nMaxVer;            // highest version inclusive
     std::set<std::string> setSubVer;  // empty matches all
-    int nPriority;
+    int32_t nPriority;
 
     // Actions
     std::string strComment;
index a2b9731..392375a 100644 (file)
@@ -74,7 +74,7 @@ namespace Checkpoints
 class CUnsignedSyncCheckpoint
 {
 public:
-    int nVersion;
+    int32_t nVersion;
     uint256 hashCheckpoint;      // checkpoint block
 
     IMPLEMENT_SERIALIZE
@@ -94,7 +94,7 @@ public:
     {
         return strprintf(
                 "CSyncCheckpoint(\n"
-                "    nVersion       = %d\n"
+                "    nVersion       = %" PRId32 "\n"
                 "    hashCheckpoint = %s\n"
                 ")\n",
             nVersion,
index 25766a4..0358b95 100644 (file)
@@ -2992,7 +2992,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CClientUIInterface& uiInterface)
                                 }
                                 catch (const std::exception&)
                                 {
-                                    printf("LoadExternalBlockFile() : Deserialize error caught at the position %" PRId64 ", this block may be truncated.", nPos);
+                                    printf("LoadExternalBlockFile() : Deserialize error caught at the position %" PRIu32 ", this block may be truncated.", nPos);
                                     SeekToNext();
                                     break;
                                 }
index 17c52c7..2d7d7cd 100644 (file)
@@ -190,7 +190,7 @@ public:
         if (IsNull())
             return "null";
         else
-            return strprintf("(nFile=%u, nBlockPos=%u, nTxPos=%u)", nFile, nBlockPos, nTxPos);
+            return strprintf("(nFile=%" PRIu32 ", nBlockPos=%" PRIu32 ", nTxPos=%" PRIu32 ")", nFile, nBlockPos, nTxPos);
     }
 
     void print() const
@@ -246,7 +246,7 @@ public:
 
     string ToString() const
     {
-        return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10).c_str(), n);
+        return strprintf("COutPoint(%s, %" PRIu32 ")", hash.ToString().substr(0,10).c_str(), n);
     }
 
     void print() const
@@ -327,7 +327,7 @@ public:
         else
             str += strprintf(", scriptSig=%s", scriptSig.ToString().substr(0,24).c_str());
         if (nSequence != numeric_limits<unsigned int>::max())
-            str += strprintf(", nSequence=%u", nSequence);
+            str += strprintf(", nSequence=%" PRIu32, nSequence);
         str += ")";
         return str;
     }
@@ -965,9 +965,9 @@ public:
         if (nHeight >= 9689 || fTestNet)
         {
             // Take last bit of block hash as entropy bit
-            unsigned int nEntropyBit = (GetHash().Get64()) & (uint64_t)1;
+            auto nEntropyBit = (GetHash().Get32()) & (uint32_t)1;
             if (fDebug && GetBoolArg("-printstakemodifier"))
-                printf("GetStakeEntropyBit: nTime=%u hashBlock=%s nEntropyBit=%u\n", nTime, GetHash().ToString().c_str(), nEntropyBit);
+                printf("GetStakeEntropyBit: nTime=%" PRIu32 " hashBlock=%s nEntropyBit=%" PRIu32 "\n", nTime, GetHash().ToString().c_str(), nEntropyBit);
             return nEntropyBit;
         }
 
@@ -975,9 +975,9 @@ public:
         int nBitNum = nHeight & 0xFF;
         int nItemNum = nHeight / 0xFF;
 
-        unsigned int nEntropyBit = (unsigned int) ((entropyStore[nItemNum] & (uint256(1) << nBitNum)) >> nBitNum).Get64();
+        auto nEntropyBit = ((entropyStore[nItemNum] & (uint256(1) << nBitNum)) >> nBitNum).Get32();
         if (fDebug && GetBoolArg("-printstakemodifier"))
-            printf("GetStakeEntropyBit: from pregenerated table, nHeight=%d nEntropyBit=%u\n", nHeight, nEntropyBit);
+            printf("GetStakeEntropyBit: from pregenerated table, nHeight=%" PRIu32 " nEntropyBit=%" PRIu32 "\n", nHeight, nEntropyBit);
         return nEntropyBit;
     }
 
@@ -996,7 +996,6 @@ public:
     {
         if (IsProofOfStake())
             return { vtx[1].vin[0].prevout, vtx[1].nTime };
-
         return { COutPoint(), (unsigned int)0 };
     }
 
@@ -1004,7 +1003,7 @@ public:
     int64_t GetMaxTransactionTime() const
     {
         int64_t maxTransactionTime = 0;
-        for(const auto& tx :  vtx)
+        for(const auto& tx : vtx)
             maxTransactionTime = max(maxTransactionTime, (int64_t)tx.nTime);
         return maxTransactionTime;
     }
@@ -1116,7 +1115,7 @@ public:
 
     void print() const
     {
-        printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%" PRIszu ", vchBlockSig=%s)\n",
+        printf("CBlock(hash=%s, ver=%" PRId32 ", hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%" PRIu32 ", nBits=%08x, nNonce=%" PRIu32 ", vtx=%" PRIszu ", vchBlockSig=%s)\n",
             GetHash().ToString().c_str(),
             nVersion,
             hashPrevBlock.ToString().c_str(),
index 58166ce..89b3e98 100644 (file)
@@ -1157,11 +1157,11 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
 
 
 
-uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
+uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, uint32_t nIn, int nHashType)
 {
     if (nIn >= txTo.vin.size())
     {
-        printf("ERROR: SignatureHash() : nIn=%d out of range\n", nIn);
+        printf("ERROR: SignatureHash() : nIn=%" PRIu32 " out of range\n", nIn);
         return 1;
     }
     CTransaction txTmp(txTo);
@@ -1189,10 +1189,10 @@ uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int
     else if ((nHashType & 0x1f) == SIGHASH_SINGLE)
     {
         // Only lock-in the txout payee at same index as txin
-        unsigned int nOut = nIn;
+        uint32_t nOut = nIn;
         if (nOut >= txTmp.vout.size())
         {
-            printf("ERROR: SignatureHash() : nOut=%d out of range\n", nOut);
+            printf("ERROR: SignatureHash() : nOut=%" PRIu32 " out of range\n", nOut);
             return 1;
         }
         txTmp.vout.resize(nOut+1);