From 6f895c2539c4ddefce658bb2ec7083774bbbd5a3 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Sun, 28 Dec 2014 02:45:19 +0300 Subject: [PATCH] Use fixed data types for some basic structures --- src/base58.h | 4 +- src/bignum.h | 61 +++++++++++++++++++---------------------- src/kernel.cpp | 12 ++++---- src/kernel.h | 18 ++++++------ src/main.h | 48 ++++++++++++++++---------------- src/net.cpp | 2 +- src/net.h | 18 ++++++------ src/qt/multisiginputentry.cpp | 6 ++-- src/script.cpp | 6 ++-- src/script.h | 47 +++++++++++++++---------------- 10 files changed, 108 insertions(+), 114 deletions(-) diff --git a/src/base58.h b/src/base58.h index e3dc380..5675c04 100644 --- a/src/base58.h +++ b/src/base58.h @@ -51,7 +51,7 @@ inline std::string EncodeBase58(const unsigned char* pbegin, const unsigned char if (!BN_div(&dv, &rem, &bn, &bn58, pctx)) throw bignum_error("EncodeBase58 : BN_div failed"); bn = dv; - unsigned int c = rem.getulong(); + unsigned int c = rem.getuint32(); str += pszBase58[c]; } @@ -94,7 +94,7 @@ inline bool DecodeBase58(const char* psz, std::vector& vchRet) return false; break; } - bnChar.setulong(p1 - pszBase58); + bnChar.setuint32(p1 - pszBase58); if (!BN_mul(&bn, &bn, &bn58, pctx)) throw bignum_error("DecodeBase58 : BN_mul failed"); bn += bnChar; diff --git a/src/bignum.h b/src/bignum.h index 1042758..e3e60f5 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -77,17 +77,17 @@ public: BN_clear_free(this); } - //CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'. - CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(unsigned char n) { BN_init(this); setulong(n); } - CBigNum(unsigned short n) { BN_init(this); setulong(n); } - CBigNum(unsigned int n) { BN_init(this); setulong(n); } - CBigNum(unsigned long n) { BN_init(this); setulong(n); } - explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); } + CBigNum(int8_t n) { BN_init(this); if (n >= 0) setuint32(n); else setint64(n); } + CBigNum(int16_t n) { BN_init(this); if (n >= 0) setuint32(n); else setint64(n); } + CBigNum(int32_t n) { BN_init(this); if (n >= 0) setuint32(n); else setint64(n); } + CBigNum(int64_t n) { BN_init(this); if (n >= 0) setuint64(n); else setint64(n); } + + CBigNum(uint8_t n) { BN_init(this); setuint32(n); } + CBigNum(uint16_t n) { BN_init(this); setuint32(n); } + CBigNum(uint32_t n) { BN_init(this); setuint32(n); } + CBigNum(uint64_t n) { BN_init(this); setuint64(n); } + explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); } explicit CBigNum(const std::vector& vch) { BN_init(this); @@ -128,29 +128,24 @@ public: } - void setulong(unsigned long n) + void setuint32(uint32_t n) { if (!BN_set_word(this, n)) - throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed"); - } - - unsigned long getulong() const - { - return BN_get_word(this); + throw bignum_error("CBigNum conversion from uint32_t : BN_set_word failed"); } - unsigned int getuint() const + uint32_t getuint32() const { return BN_get_word(this); } - int getint() const + int32_t getint32() const { - unsigned long n = BN_get_word(this); + uint64_t n = BN_get_word(this); if (!BN_is_negative(this)) - return (n > (unsigned long)std::numeric_limits::max() ? std::numeric_limits::max() : n); + return (n > (uint64_t)std::numeric_limits::max() ? std::numeric_limits::max() : n); else - return (n > (unsigned long)std::numeric_limits::max() ? std::numeric_limits::min() : -(int)n); + return (n > (uint64_t)std::numeric_limits::max() ? std::numeric_limits::min() : -(int32_t)n); } void setint64(int64_t sn) @@ -188,7 +183,7 @@ public: } *p++ = c; } - unsigned int nSize = p - (pch + 4); + uint32_t nSize = p - (pch + 4); pch[0] = (nSize >> 24) & 0xff; pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; @@ -230,7 +225,7 @@ public: } *p++ = c; } - unsigned int nSize = p - (pch + 4); + uint32_t nSize = p - (pch + 4); pch[0] = (nSize >> 24) & 0xff; pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; @@ -258,7 +253,7 @@ public: } *p++ = c; } - unsigned int nSize = p - (pch + 4); + uint32_t nSize = p - (pch + 4); pch[0] = (nSize >> 24) & 0xff; pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; @@ -301,7 +296,7 @@ public: } *p++ = c; } - unsigned int nSize = p - (pch + 4); + uint32_t nSize = p - (pch + 4); pch[0] = (nSize >> 24) & 0xff; pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; @@ -346,7 +341,7 @@ public: void setvch(const std::vector& vch) { std::vector vch2(vch.size() + 4); - unsigned int nSize = vch.size(); + uint32_t nSize = vch.size(); // BIGNUM's byte stream format expects 4 bytes of // big endian size data info at the front vch2[0] = (nSize >> 24) & 0xff; @@ -370,9 +365,9 @@ public: return vch; } - CBigNum& SetCompact(unsigned int nCompact) + CBigNum& SetCompact(uint32_t nCompact) { - unsigned int nSize = nCompact >> 24; + uint32_t nSize = nCompact >> 24; std::vector vch(4 + nSize); vch[3] = nSize; if (nSize >= 1) vch[4] = (nCompact >> 16) & 0xff; @@ -382,13 +377,13 @@ public: return *this; } - unsigned int GetCompact() const + uint32_t GetCompact() const { - unsigned int nSize = BN_bn2mpi(this, NULL); + uint32_t nSize = BN_bn2mpi(this, NULL); std::vector vch(nSize); nSize -= 4; BN_bn2mpi(this, &vch[0]); - unsigned int nCompact = nSize << 24; + uint32_t nCompact = nSize << 24; if (nSize >= 1) nCompact |= (vch[4] << 16); if (nSize >= 2) nCompact |= (vch[5] << 8); if (nSize >= 3) nCompact |= (vch[6] << 0); @@ -442,7 +437,7 @@ public: if (!BN_div(&dv, &rem, &bn, &bnBase, pctx)) throw bignum_error("CBigNum::ToString() : BN_div failed"); bn = dv; - unsigned int c = rem.getulong(); + unsigned int c = rem.getuint32(); str += "0123456789abcdef"[c]; } if (BN_is_negative(this)) diff --git a/src/kernel.cpp b/src/kernel.cpp index 46d8ac0..b326d89 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -330,12 +330,12 @@ bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifier) // quantities so as to generate blocks faster, degrading the system back into // a proof-of-work situation. // -bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned int nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, unsigned int nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake) +bool CheckStakeKernelHash(uint32_t nBits, const CBlock& blockFrom, uint32_t nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, uint32_t nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake) { if (nTimeTx < txPrev.nTime) // Transaction timestamp violation return error("CheckStakeKernelHash() : nTime violation"); - unsigned int nTimeBlockFrom = blockFrom.GetBlockTime(); + uint32_t nTimeBlockFrom = blockFrom.GetBlockTime(); if (nTimeBlockFrom + nStakeMinAge > nTimeTx) // Min age requirement return error("CheckStakeKernelHash() : min age violation"); @@ -392,7 +392,7 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned } // Scan given coins set for kernel solution -bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, unsigned int &nTimeTx, unsigned int &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried) +bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, uint32_t &nTimeTx, uint32_t &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried) { uint256 hashProofOfStake = 0; @@ -416,7 +416,7 @@ bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, Co continue; // Transaction offset inside block - unsigned int nTxOffset = txindex.pos.nTxPos - txindex.pos.nBlockPos; + uint32_t nTxOffset = txindex.pos.nTxPos - txindex.pos.nBlockPos; // Current timestamp scanning interval unsigned int nCurrentSearchInterval = min((int64_t)settings.nSearchInterval, (int64_t)nMaxStakeSearchInterval); @@ -502,7 +502,7 @@ bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hash } // Get stake modifier checksum -unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex) +uint32_t GetStakeModifierChecksum(const CBlockIndex* pindex) { assert (pindex->pprev || pindex->GetBlockHash() == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet)); // Hash previous checksum with flags, hashProofOfStake and nStakeModifier @@ -516,7 +516,7 @@ unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex) } // Check stake modifier hard checkpoints -bool CheckStakeModifierCheckpoints(int nHeight, unsigned int nStakeModifierChecksum) +bool CheckStakeModifierCheckpoints(int nHeight, uint32_t nStakeModifierChecksum) { MapModifierCheckpoints& checkpoints = (fTestNet ? mapStakeModifierCheckpointsTestNet : mapStakeModifierCheckpoints); diff --git a/src/kernel.h b/src/kernel.h index 9ee2ce1..e784f2a 100644 --- a/src/kernel.h +++ b/src/kernel.h @@ -31,15 +31,15 @@ bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifier); // Check whether stake kernel meets hash target // Sets hashProofOfStake on success return -bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned int nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, unsigned int nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake=false); +bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, uint32_t nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, uint32_t nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake=false); // Coins scanning options typedef struct KernelSearchSettings { - unsigned int nBits; // Packed difficulty - unsigned int nTime; // Basic time - unsigned int nOffset; // Offset inside CoinsSet (isn't used yet) - unsigned int nLimit; // Coins to scan (isn't used yet) - unsigned int nSearchInterval; // Number of seconds allowed to go into the past + uint32_t nBits; // Packed difficulty + uint32_t nTime; // Basic time + uint32_t nOffset; // Offset inside CoinsSet (isn't used yet) + uint32_t nLimit; // Coins to scan (isn't used yet) + uint32_t nSearchInterval; // Number of seconds allowed to go into the past } KernelSearchSettings; typedef std::set > CoinsSet; @@ -49,17 +49,17 @@ typedef std::set > CoinsSet; typedef std::map, std::pair >, std::pair > > MetaMap; // Scan given coins set for kernel solution -bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, unsigned int &nTimeTx, unsigned int &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried); +bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, uint32_t &nTimeTx, uint32_t &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried); // Check kernel hash target and coinstake signature // Sets hashProofOfStake on success return bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hashProofOfStake, uint256& targetProofOfStake); // Get stake modifier checksum -unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex); +uint32_t GetStakeModifierChecksum(const CBlockIndex* pindex); // Check stake modifier hard checkpoints -bool CheckStakeModifierCheckpoints(int nHeight, unsigned int nStakeModifierChecksum); +bool CheckStakeModifierCheckpoints(int nHeight, uint32_t nStakeModifierChecksum); // Get time weight using supplied timestamps int64_t GetWeight(int64_t nIntervalBeginning, int64_t nIntervalEnd); diff --git a/src/main.h b/src/main.h index 574bddd..0c54e7e 100644 --- a/src/main.h +++ b/src/main.h @@ -152,9 +152,9 @@ bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut); class CDiskTxPos { public: - unsigned int nFile; - unsigned int nBlockPos; - unsigned int nTxPos; + uint32_t nFile; + uint32_t nBlockPos; + uint32_t nTxPos; CDiskTxPos() { @@ -206,7 +206,7 @@ class CInPoint { public: CTransaction* ptx; - unsigned int n; + uint32_t n; CInPoint() { SetNull(); } CInPoint(CTransaction* ptxIn, unsigned int nIn) { ptx = ptxIn; n = nIn; } @@ -221,7 +221,7 @@ class COutPoint { public: uint256 hash; - unsigned int n; + uint32_t n; COutPoint() { SetNull(); } COutPoint(uint256 hashIn, unsigned int nIn) { hash = hashIn; n = nIn; } @@ -267,7 +267,7 @@ class CTxIn public: COutPoint prevout; CScript scriptSig; - unsigned int nSequence; + uint32_t nSequence; CTxIn() { @@ -444,10 +444,10 @@ class CTransaction public: static const int CURRENT_VERSION=1; int nVersion; - unsigned int nTime; + uint32_t nTime; std::vector vin; std::vector vout; - unsigned int nLockTime; + uint32_t nLockTime; // Denial-of-service detection: mutable int nDoS; @@ -758,7 +758,7 @@ class CMerkleTx : public CTransaction public: uint256 hashBlock; std::vector vMerkleBranch; - int nIndex; + int32_t nIndex; // memory only mutable bool fMerkleVerified; @@ -877,12 +877,12 @@ class CBlock public: // header static const int CURRENT_VERSION=6; - int nVersion; + int32_t nVersion; uint256 hashPrevBlock; uint256 hashMerkleRoot; - unsigned int nTime; - unsigned int nBits; - unsigned int nNonce; + uint32_t nTime; + uint32_t nBits; + uint32_t nNonce; // network and disk std::vector vtx; @@ -1163,15 +1163,15 @@ public: const uint256* phashBlock; CBlockIndex* pprev; CBlockIndex* pnext; - unsigned int nFile; - unsigned int nBlockPos; + uint32_t nFile; + uint32_t nBlockPos; uint256 nChainTrust; // ppcoin: trust score of block chain - int nHeight; + int32_t nHeight; int64_t nMint; int64_t nMoneySupply; - unsigned int nFlags; // ppcoin: block index flags + uint32_t nFlags; // ppcoin: block index flags enum { BLOCK_PROOF_OF_STAKE = (1 << 0), // is proof-of-stake block @@ -1180,19 +1180,19 @@ public: }; uint64_t nStakeModifier; // hash modifier for proof-of-stake - unsigned int nStakeModifierChecksum; // checksum of index; in-memeory only + uint32_t nStakeModifierChecksum; // checksum of index; in-memeory only // proof-of-stake specific fields COutPoint prevoutStake; - unsigned int nStakeTime; + uint32_t nStakeTime; uint256 hashProofOfStake; // block header - int nVersion; - uint256 hashMerkleRoot; - unsigned int nTime; - unsigned int nBits; - unsigned int nNonce; + int32_t nVersion; + uint256 hashMerkleRoot; + uint32_t nTime; + uint32_t nBits; + uint32_t nNonce; CBlockIndex() { diff --git a/src/net.cpp b/src/net.cpp index 5b3f9b8..941bcd8 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1150,7 +1150,7 @@ void ThreadDNSAddressSeed2(void* parg) -unsigned int pnSeed[] = +uint32_t pnSeed[] = { 0x5360a653, 0x6c47bb25, 0x52568c5f, 0xc6f5c851, 0x6f17f3a2, 0x1d52a9d5, 0x2c1544c1, 0xb8748368, 0x055d6ac1, 0x2490bb25, 0x614488d5, 0xa463f8a2, 0xc54c1256, 0xf72d9252, 0x548432c6, 0xade08368, diff --git a/src/net.h b/src/net.h index 369d4fd..60c5274 100644 --- a/src/net.h +++ b/src/net.h @@ -141,12 +141,12 @@ public: int64_t nLastRecv; int64_t nTimeConnected; std::string addrName; - int nVersion; + int32_t nVersion; std::string strSubVer; bool fInbound; int64_t nReleaseTime; - int nStartingHeight; - int nMisbehavior; + int32_t nStartingHeight; + int32_t nMisbehavior; uint64_t nSendBytes; uint64_t nRecvBytes; bool fSyncNode; @@ -173,12 +173,12 @@ public: int64_t nLastRecv; int64_t nLastSendEmpty; int64_t nTimeConnected; - int nHeaderStart; - unsigned int nMessageStart; + int32_t nHeaderStart; + uint32_t nMessageStart; CAddress addr; std::string addrName; CService addrLocal; - int nVersion; + int32_t nVersion; std::string strSubVer; bool fOneShot; bool fClient; @@ -203,7 +203,7 @@ public: uint256 hashContinue; CBlockIndex* pindexLastGetBlocksBegin; uint256 hashLastGetBlocksEnd; - int nStartingHeight; + int32_t nStartingHeight; bool fStartSync; // flood relay @@ -392,12 +392,12 @@ public: return; // Set the size - unsigned int nSize = vSend.size() - nMessageStart; + uint32_t nSize = vSend.size() - nMessageStart; memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::MESSAGE_SIZE_OFFSET, &nSize, sizeof(nSize)); // Set the checksum uint256 hash = Hash(vSend.begin() + nMessageStart, vSend.end()); - unsigned int nChecksum = 0; + uint32_t nChecksum = 0; memcpy(&nChecksum, &hash, sizeof(nChecksum)); assert(nMessageStart - nHeaderStart >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum)); memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::CHECKSUM_OFFSET, &nChecksum, sizeof(nChecksum)); diff --git a/src/qt/multisiginputentry.cpp b/src/qt/multisiginputentry.cpp index 89653d2..23458c2 100644 --- a/src/qt/multisiginputentry.cpp +++ b/src/qt/multisiginputentry.cpp @@ -43,7 +43,7 @@ bool MultisigInputEntry::validate() CTxIn MultisigInputEntry::getInput() { - int nOutput = ui->transactionOutput->currentIndex(); + unsigned int nOutput = ui->transactionOutput->currentIndex(); CTxIn input(COutPoint(txHash, nOutput)); return input; @@ -52,7 +52,7 @@ CTxIn MultisigInputEntry::getInput() int64_t MultisigInputEntry::getAmount() { int64_t amount = 0; - int nOutput = ui->transactionOutput->currentIndex(); + unsigned int nOutput = ui->transactionOutput->currentIndex(); CTransaction tx; uint256 blockHash = 0; @@ -115,7 +115,7 @@ void MultisigInputEntry::on_transactionId_textChanged(const QString &transaction uint256 blockHash = 0; if(!GetTransaction(txHash, tx, blockHash)) return; - for(int i = 0; i < tx.vout.size(); i++) + for(unsigned int i = 0; i < tx.vout.size(); i++) { QString idStr; idStr.setNum(i); diff --git a/src/script.cpp b/src/script.cpp index 44f77ae..7b25637 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -625,7 +625,7 @@ bool EvalScript(vector >& stack, const CScript& script, co // (xn ... x2 x1 x0 n - ... x2 x1 x0 xn) if (stack.size() < 2) return false; - int n = CastToBigNum(stacktop(-1)).getint(); + int n = CastToBigNum(stacktop(-1)).getint32(); popstack(stack); if (n < 0 || n >= (int)stack.size()) return false; @@ -901,7 +901,7 @@ bool EvalScript(vector >& stack, const CScript& script, co if ((int)stack.size() < i) return false; - int nKeysCount = CastToBigNum(stacktop(-i)).getint(); + int nKeysCount = CastToBigNum(stacktop(-i)).getint32(); if (nKeysCount < 0 || nKeysCount > 20) return false; nOpCount += nKeysCount; @@ -912,7 +912,7 @@ bool EvalScript(vector >& stack, const CScript& script, co if ((int)stack.size() < i) return false; - int nSigsCount = CastToBigNum(stacktop(-i)).getint(); + int nSigsCount = CastToBigNum(stacktop(-i)).getint32(); if (nSigsCount < 0 || nSigsCount > nKeysCount) return false; int isig = ++i; diff --git a/src/script.h b/src/script.h index ec66e55..f129848 100644 --- a/src/script.h +++ b/src/script.h @@ -241,7 +241,7 @@ const char* GetOpName(opcodetype opcode); inline std::string ValueString(const std::vector& vch) { if (vch.size() <= 4) - return strprintf("%d", CBigNum(vch).getint()); + return strprintf("%d", CBigNum(vch).getint32()); else return HexStr(vch); } @@ -318,16 +318,15 @@ public: return ret; } + explicit CScript(int8_t b) { operator<<(b); } + explicit CScript(int16_t b) { operator<<(b); } + explicit CScript(int32_t b) { operator<<(b); } + explicit CScript(int64_t b) { operator<<(b); } - //explicit CScript(char b) is not portable. Use 'signed char' or 'unsigned char'. - explicit CScript(signed char b) { operator<<(b); } - explicit CScript(short b) { operator<<(b); } - explicit CScript(int b) { operator<<(b); } - explicit CScript(long b) { operator<<(b); } - explicit CScript(unsigned char b) { operator<<(b); } - explicit CScript(unsigned int b) { operator<<(b); } - explicit CScript(unsigned short b) { operator<<(b); } - explicit CScript(unsigned long b) { operator<<(b); } + explicit CScript(uint8_t b) { operator<<(b); } + explicit CScript(uint16_t b) { operator<<(b); } + explicit CScript(uint32_t b) { operator<<(b); } + explicit CScript(uint64_t b) { operator<<(b); } explicit CScript(opcodetype b) { operator<<(b); } explicit CScript(const uint256& b) { operator<<(b); } @@ -335,15 +334,15 @@ public: explicit CScript(const std::vector& b) { operator<<(b); } - //CScript& operator<<(char b) is not portable. Use 'signed char' or 'unsigned char'. - CScript& operator<<(signed char b) { return push_int64(b); } - CScript& operator<<(short b) { return push_int64(b); } - CScript& operator<<(int b) { return push_int64(b); } - CScript& operator<<(long b) { return push_int64(b); } - CScript& operator<<(unsigned char b) { return push_uint64(b); } - CScript& operator<<(unsigned int b) { return push_uint64(b); } - CScript& operator<<(unsigned short b) { return push_uint64(b); } - CScript& operator<<(unsigned long b) { return push_uint64(b); } + CScript& operator<<(int8_t b) { return push_int64(b); } + CScript& operator<<(int16_t b) { return push_int64(b); } + CScript& operator<<(int32_t b) { return push_int64(b); } + CScript& operator<<(int64_t b) { return push_int64(b); } + + CScript& operator<<(uint8_t b) { return push_uint64(b); } + CScript& operator<<(uint16_t b) { return push_uint64(b); } + CScript& operator<<(uint32_t b) { return push_uint64(b); } + CScript& operator<<(uint64_t b) { return push_uint64(b); } CScript& operator<<(opcodetype opcode) { @@ -379,27 +378,27 @@ public: return *this; } - CScript& operator<<(const std::vector& b) + CScript& operator<<(const std::vector& b) { if (b.size() < OP_PUSHDATA1) { - insert(end(), (unsigned char)b.size()); + insert(end(), (uint8_t)b.size()); } else if (b.size() <= 0xff) { insert(end(), OP_PUSHDATA1); - insert(end(), (unsigned char)b.size()); + insert(end(), (uint8_t)b.size()); } else if (b.size() <= 0xffff) { insert(end(), OP_PUSHDATA2); - unsigned short nSize = b.size(); + uint16_t nSize = b.size(); insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize)); } else { insert(end(), OP_PUSHDATA4); - unsigned int nSize = b.size(); + uint32_t nSize = b.size(); insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize)); } insert(end(), b.begin(), b.end()); -- 1.7.1