From e99746948f826bdf548b6ded3f98990c26afeb5f Mon Sep 17 00:00:00 2001 From: Douglas Roark Date: Wed, 14 Nov 2018 17:20:47 -0800 Subject: [PATCH] Fix header warnings (Part 1) Armory has a *lot* of warnings in its C++ code (not including third-party code, which is typically not touched). Start the process of fixing the warnings, starting with header files (more annoying as they can occur over & over). Warnings fixed include but are not limited to: -Wreorder, -Wunused-parameter, -Wformat-nonliteral, and -Wsign-compare --- cppForSwig/AsyncClient.h | 19 ++-- cppForSwig/BinaryData.h | 6 +- cppForSwig/BtcUtils.h | 196 +++++++++++++++++++-------------------- cppForSwig/log.h | 38 ++++---- 4 files changed, 129 insertions(+), 130 deletions(-) diff --git a/cppForSwig/AsyncClient.h b/cppForSwig/AsyncClient.h index 32083f803..b99047e1e 100644 --- a/cppForSwig/AsyncClient.h +++ b/cppForSwig/AsyncClient.h @@ -36,7 +36,8 @@ class ClientMessageError : public std::runtime_error }; /////////////////////////////////////////////////////////////////////////////// -template class ReturnMessage +template +class ReturnMessage { private: U value_; @@ -108,9 +109,9 @@ namespace AsyncClient class LedgerDelegate { private: + std::shared_ptr sock_; std::string delegateID_; std::string bdvID_; - std::shared_ptr sock_; public: LedgerDelegate(void) {} @@ -131,17 +132,17 @@ namespace AsyncClient friend class ::WalletContainer; private: + const std::shared_ptr sock_; const std::string bdvID_; const std::string walletID_; const BinaryData scrAddr_; + const int index_; BinaryData addrHash_; - const std::shared_ptr sock_; const uint64_t fullBalance_; const uint64_t spendableBalance_; const uint64_t unconfirmedBalance_; const uint32_t count_; - const int index_; std::string comment_; @@ -182,9 +183,9 @@ namespace AsyncClient friend class ScrAddrObj; protected: + const std::shared_ptr sock_; const std::string walletID_; const std::string bdvID_; - const std::shared_ptr sock_; public: BtcWallet(const BlockDataViewer&, const std::string&); @@ -403,9 +404,9 @@ struct CallbackReturn_String : public CallbackReturn_WebSocket struct CallbackReturn_LedgerDelegate : public CallbackReturn_WebSocket { private: - std::function)> userCallbackLambda_; std::shared_ptr sockPtr_; const std::string& bdvID_; + std::function)> userCallbackLambda_; public: CallbackReturn_LedgerDelegate( @@ -422,9 +423,9 @@ struct CallbackReturn_LedgerDelegate : public CallbackReturn_WebSocket struct CallbackReturn_Tx : public CallbackReturn_WebSocket { private: - std::function)> userCallbackLambda_; std::shared_ptr cache_; BinaryData txHash_; + function)> userCallbackLambda_; public: CallbackReturn_Tx(std::shared_ptr cache, @@ -440,10 +441,10 @@ struct CallbackReturn_Tx : public CallbackReturn_WebSocket struct CallbackReturn_RawHeader : public CallbackReturn_WebSocket { private: - std::function)> userCallbackLambda_; std::shared_ptr cache_; BinaryData txHash_; unsigned height_; + function)> userCallbackLambda_; public: CallbackReturn_RawHeader( @@ -659,8 +660,8 @@ struct CallbackReturn_Bool : public CallbackReturn_WebSocket struct CallbackReturn_BlockHeader : public CallbackReturn_WebSocket { private: - std::function)> userCallbackLambda_; const unsigned height_; + std::function)> userCallbackLambda_; public: CallbackReturn_BlockHeader(unsigned height, diff --git a/cppForSwig/BinaryData.h b/cppForSwig/BinaryData.h index d68bd357e..f29637dbf 100644 --- a/cppForSwig/BinaryData.h +++ b/cppForSwig/BinaryData.h @@ -952,7 +952,7 @@ class BinaryReader ///////////////////////////////////////////////////////////////////////////// - uint8_t get_uint8_t(ENDIAN e=LE) + uint8_t get_uint8_t() { uint8_t outVal = bdStr_[pos_]; pos_ += 1; @@ -1134,7 +1134,7 @@ class BinaryRefReader ///////////////////////////////////////////////////////////////////////////// - uint8_t get_uint8_t(ENDIAN e=LE) + uint8_t get_uint8_t() { if (getSizeRemaining() < 1) { @@ -1443,7 +1443,7 @@ class BinaryWriter ///////////////////////////////////////////////////////////////////////////// // These write data properly regardless of the architecture - void put_uint8_t (const uint8_t& val, ENDIAN e=LE) { theString_.append( val ); } + void put_uint8_t (const uint8_t& val) { theString_.append( val ); } ///// void put_uint16_t(const uint16_t& val, ENDIAN e=LE) diff --git a/cppForSwig/BtcUtils.h b/cppForSwig/BtcUtils.h index c0b267dfb..c03bd53af 100644 --- a/cppForSwig/BtcUtils.h +++ b/cppForSwig/BtcUtils.h @@ -5,9 +5,9 @@ // See LICENSE-ATI or http://www.gnu.org/licenses/agpl.html // // // // // -// Copyright (C) 2016, goatpig // +// Copyright (C) 2016, goatpig // // Distributed under the MIT license // -// See LICENSE-MIT or https://opensource.org/licenses/MIT // +// See LICENSE-MIT or https://opensource.org/licenses/MIT // // // //////////////////////////////////////////////////////////////////////////////// @@ -42,7 +42,7 @@ #define MIN_CONFIRMATIONS 6 #define COINBASE_MATURITY 120 -#define TX_0_UNCONFIRMED 0 +#define TX_0_UNCONFIRMED 0 #define TX_NOT_EXIST -1 #define TX_OFF_MAIN_BRANCH -2 @@ -69,8 +69,8 @@ #define MSIGPREFIX WRITE_UINT8_LE((uint8_t)SCRIPT_PREFIX_MULTISIG) #define NONSTDPREFIX WRITE_UINT8_LE((uint8_t)SCRIPT_PREFIX_NONSTD) -// Really, these defs are just for making it painfully clear in the -// code what you are attempting to compare. I'm constantly messing +// Really, these defs are just for making it painfully clear in the +// code what you are attempting to compare. I'm constantly messing // up == and != when trying to read through the code. #define KEY_NOT_IN_MAP(KEY,MAP) (MAP.find(KEY) == MAP.end()) #define KEY_IN_MAP(KEY,MAP) (MAP.find(KEY) != MAP.end()) @@ -272,7 +272,7 @@ class DERException : public std::runtime_error #define BIP32_SER_VERSION_TEST_PRV 0x043587CF #define BIP32_SER_VERSION_TEST_PUB 0x04358394 -// This class holds only static methods. +// This class holds only static methods. // NOTE: added default ctor and a few non-static, to support SWIG // (-classic SWIG doesn't support static methods) class BtcUtils @@ -283,7 +283,7 @@ class BtcUtils public: static const BinaryData EmptyHash_; - + // Block of code to be called by SWIG -- i.e. made available to python BtcUtils(void) {} static BinaryData hash256(BinaryData const & str) {return getHash256(str);} @@ -294,7 +294,7 @@ class BtcUtils static const BinaryData& EmptyHash() { return EmptyHash_; } ///////////////////////////////////////////////////////////////////////////// - static uint64_t readVarInt(uint8_t const * strmPtr, size_t remaining, + static uint64_t readVarInt(uint8_t const * strmPtr, size_t remaining, uint32_t* lenOutPtr=NULL) { if (remaining < 1) @@ -303,7 +303,7 @@ class BtcUtils if(firstByte < 0xfd) { - if(lenOutPtr != NULL) + if(lenOutPtr != NULL) *lenOutPtr = 1; return firstByte; } @@ -311,16 +311,16 @@ class BtcUtils { if (remaining < 3) throw BlockDeserializingException("invalid varint"); - if(lenOutPtr != NULL) + if(lenOutPtr != NULL) *lenOutPtr = 3; return READ_UINT16_LE(strmPtr+1); - + } else if(firstByte == 0xfe) { if (remaining < 5) throw BlockDeserializingException("invalid varint"); - if(lenOutPtr != NULL) + if(lenOutPtr != NULL) *lenOutPtr = 5; return READ_UINT32_LE(strmPtr+1); } @@ -328,7 +328,7 @@ class BtcUtils { if (remaining < 9) throw BlockDeserializingException("invalid varint"); - if(lenOutPtr != NULL) + if(lenOutPtr != NULL) *lenOutPtr = 9; return READ_UINT64_LE(strmPtr+1); } @@ -343,7 +343,7 @@ class BtcUtils brr.advance(outLen); return std::pair(outVal, (uint8_t)outLen); } - + ///////////////////////////////////////////////////////////////////////////// static inline uint32_t readVarIntLength(uint8_t const * strmPtr) { @@ -386,7 +386,7 @@ class BtcUtils std::ifstream is(OS_TranslatePath(filename.c_str()), std::ios::in| std::ios::binary); if(!is.is_open()) return FILE_DOES_NOT_EXIST; - + is.seekg(0, std::ios::end); uint64_t filesize = (size_t)is.tellg(); is.close(); @@ -407,19 +407,19 @@ class BtcUtils num = (num - bottom3) / 1000; } while(num>=1); - + std::stringstream out; out << (fullNum < 0 ? "-" : ""); size_t nt = triplets.size()-1; char t[4]; for(uint32_t i=0; i<=nt; i++) { - if(i==0) - sprintf(t, "%d", triplets[nt-i]); - else - sprintf(t, "%03d", triplets[nt-i]); + if(i==0) + sprintf(t, "%d", triplets[nt-i]); + else + sprintf(t, "%03d", triplets[nt-i]); out << std::string(t); - + if(i != nt) out << ","; } @@ -459,8 +459,8 @@ class BtcUtils } ///////////////////////////////////////////////////////////////////////////// - static void getSha256(const uint8_t* data, - size_t len, + static void getSha256(const uint8_t* data, + size_t len, BinaryData& hashOutput) { if (hashOutput.getSize() != 32) @@ -469,7 +469,7 @@ class BtcUtils BinaryDataRef dataBdr(data, len); CryptoSHA2::getSha256(dataBdr, hashOutput.getPtr()); } - + ///////////////////////////////////////////////////////////////////////////// static BinaryData getSha256(const BinaryData& bd) { @@ -502,14 +502,14 @@ class BtcUtils } ///////////////////////////////////////////////////////////////////////////// - static void getHash256(BinaryData const & strToHash, + static void getHash256(BinaryData const & strToHash, BinaryData & hashOutput) { getHash256(strToHash.getPtr(), strToHash.getSize(), hashOutput); } ///////////////////////////////////////////////////////////////////////////// - static void getHash256(BinaryDataRef strToHash, + static void getHash256(BinaryDataRef strToHash, BinaryData & hashOutput) { getHash256(strToHash.getPtr(), strToHash.getSize(), hashOutput); @@ -550,7 +550,7 @@ class BtcUtils ///////////////////////////////////////////////////////////////////////////// static BinaryData getHash160(uint8_t const * strToHash, size_t nBytes) - + { BinaryData hashOutput(20); getHash160(strToHash, nBytes, hashOutput); @@ -613,10 +613,10 @@ class BtcUtils size_t numTx = txhashlist.size(); std::vector merkleTree(3*numTx); BinaryData hashInput(64); - + for(uint32_t i=0; i * offsetsIn) { BinaryRefReader brr(ptr, size); @@ -681,7 +681,7 @@ class BtcUtils (*offsetsIn)[nIn] = brr.getPosition(); // Get the end of the last } } - + static size_t TxInCalcLength(uint8_t const * ptr, size_t size) { if (size < 37) @@ -690,7 +690,7 @@ class BtcUtils uint32_t scrLen = (uint32_t)readVarInt(ptr+36, size-36, &viLen); return (36 + viLen + scrLen + 4); } - + ///////////////////////////////////////////////////////////////////////////// static size_t TxOutCalcLength(uint8_t const * ptr, size_t size) { @@ -729,8 +729,8 @@ class BtcUtils std::vector * offsetsOut, std::vector * offsetsWitness) { - BinaryRefReader brr(ptr, size); - + BinaryRefReader brr(ptr, size); + if (brr.getSizeRemaining() < 4) throw BlockDeserializingException(); // Tx Version; @@ -825,9 +825,9 @@ class BtcUtils std::vector * offsetsOut, std::vector * offsetsWitness) { - BinaryRefReader brr(ptr, len); + BinaryRefReader brr(ptr, len); + - // Tx Version; brr.advance(4); @@ -879,7 +879,7 @@ class BtcUtils for(uint32_t i=0; i splitScr = splitPushOnlyScriptRefs(script); - + if(splitScr.size() == 0) return TXIN_SCRIPT_NONSTANDARD; // TODO: Maybe should identify whether the other pushed data - // in the script is a potential solution for the + // in the script is a potential solution for the // subscript... meh? //BinaryDataRef lastObj = splitScr[splitScr.size() - 1]; if(script[2]==0x30 && script[4]==0x02) return TXIN_SCRIPT_SPENDMULTI; } - + if( !(script[1]==0x30 && script[3]==0x02) ) return TXIN_SCRIPT_NONSTANDARD; @@ -1033,7 +1033,7 @@ class BtcUtils if(script.getSize() == sigSize) return TXIN_SCRIPT_SPENDPUBKEY; - uint32_t keySizeFull = 66; // \x41 \x04 [X32] [Y32] + uint32_t keySizeFull = 66; // \x41 \x04 [X32] [Y32] uint32_t keySizeCompr= 34; // \x41 \x02 [X32] if(script.getSize() == sigSize + keySizeFull) @@ -1045,7 +1045,7 @@ class BtcUtils } ///////////////////////////////////////////////////////////////////////////// - static BinaryData getTxOutRecipientAddr(BinaryDataRef const & script, + static BinaryData getTxOutRecipientAddr(BinaryDataRef const & script, TXOUT_SCRIPT_TYPE type=TXOUT_SCRIPT_NONSTANDARD) { if(type==TXOUT_SCRIPT_NONSTANDARD) @@ -1065,7 +1065,7 @@ class BtcUtils } ///////////////////////////////////////////////////////////////////////////// - // We use this for LevelDB keys, to return same key if the same priv/pub + // We use this for LevelDB keys, to return same key if the same priv/pub // pair is used, and also saving a few bytes for common script types static BinaryData getTxOutScrAddr(BinaryDataRef script, TXOUT_SCRIPT_TYPE type = TXOUT_SCRIPT_NONSTANDARD); @@ -1105,12 +1105,12 @@ class BtcUtils ///////////////////////////////////////////////////////////////////////////// // "UniqueKey"=="ScrAddr" minus prefix // TODO: Interesting exercise: is there a non-standard script that could - // look like the output of this function operating on a multisig + // look like the output of this function operating on a multisig // script (doesn't matter if it's valid or not)? In other words, is // there is a hole where someone could mine a script that would be // forwarded by Bitcoin Core to this code, which would then produce - // a non-std-unique-key that would be indistinguishable from the - // output of this function? My guess is, no. And my guess is that + // a non-std-unique-key that would be indistinguishable from the + // output of this function? My guess is, no. And my guess is that // it's not a very useful even if it did. But it would be good to // rule it out. static BinaryData getMultisigUniqueKey(BinaryData const & script) @@ -1129,7 +1129,7 @@ class BtcUtils bw.put_uint8_t((uint8_t)N); std::sort(a160List.begin(), a160List.end()); - + for(uint32_t i=0; i & addr160List) { std::vector pkList; uint32_t M = getMultisigPubKeyList(script, pkList); size_t N = pkList.size(); - + if(M==0) return 0; @@ -1160,7 +1160,7 @@ class BtcUtils ///////////////////////////////////////////////////////////////////////////// // Returns M in M-of-N. Use pkList.size() for N. Output is sorted. - static uint8_t getMultisigPubKeyList( BinaryData const & script, + static uint8_t getMultisigPubKeyList( BinaryData const & script, std::vector & pkList) { if( script[-1] != 0xae ) @@ -1168,7 +1168,7 @@ class BtcUtils uint8_t M = script[0]; uint8_t N = script[-2]; - + if(M<81 || M>96|| N<81 || N>96) return 0; @@ -1192,7 +1192,7 @@ class BtcUtils } - + ///////////////////////////////////////////////////////////////////////////// // These two methods are basically just to make SWIG access easier static BinaryData getMultisigAddr160InfoStr( BinaryData const & script) @@ -1200,7 +1200,7 @@ class BtcUtils std::vector outVect; uint32_t M = getMultisigAddrList(script, outVect); size_t N = outVect.size(); - + BinaryWriter bw(2 + N*20); // reserve enough space for header + N addr bw.put_uint8_t((uint8_t)M); bw.put_uint8_t((uint8_t)N); @@ -1216,7 +1216,7 @@ class BtcUtils std::vector outVect; uint32_t M = getMultisigPubKeyList(script, outVect); size_t N = outVect.size(); - + BinaryWriter bw(2 + N*20); // reserve enough space for header + N addr bw.put_uint8_t((uint8_t)M); bw.put_uint8_t((uint8_t)N); @@ -1237,7 +1237,7 @@ class BtcUtils // TXIN_SCRIPT_SPENDMULTI, // TXIN_SCRIPT_SPENDP2SH, // TXIN_SCRIPT_NONSTANDARD - static BinaryData getTxInAddr(BinaryDataRef script, + static BinaryData getTxInAddr(BinaryDataRef script, BinaryDataRef prevTxHash, TXIN_SCRIPT_TYPE type=TXIN_SCRIPT_NONSTANDARD) { @@ -1253,30 +1253,30 @@ class BtcUtils { switch(type) { - case(TXIN_SCRIPT_STDUNCOMPR): + case(TXIN_SCRIPT_STDUNCOMPR): if (script.getSize() < 65) throw BlockDeserializingException(); return getHash160(script.getSliceRef(-65, 65)); - case(TXIN_SCRIPT_STDCOMPR): + case(TXIN_SCRIPT_STDCOMPR): if (script.getSize() < 33) throw BlockDeserializingException(); return getHash160(script.getSliceRef(-33, 33)); - case(TXIN_SCRIPT_SPENDP2SH): + case(TXIN_SCRIPT_SPENDP2SH): { std::vector pushVect = splitPushOnlyScriptRefs(script); return getHash160(pushVect[pushVect.size()-1]); } - case(TXIN_SCRIPT_COINBASE): - case(TXIN_SCRIPT_SPENDPUBKEY): - case(TXIN_SCRIPT_SPENDMULTI): - case(TXIN_SCRIPT_NONSTANDARD): + case(TXIN_SCRIPT_COINBASE): + case(TXIN_SCRIPT_SPENDPUBKEY): + case(TXIN_SCRIPT_SPENDMULTI): + case(TXIN_SCRIPT_NONSTANDARD): return BadAddress_; default: LOGERR << "What kind of TxIn script did we get?"; return BadAddress_; } } - + ///////////////////////////////////////////////////////////////////////////// static BinaryData getTxInAddrFromTypeInt( BinaryData const & script, uint32_t typeInt) @@ -1291,7 +1291,7 @@ class BtcUtils BinaryRefReader brr(script); uint8_t nextOp; - + while(brr.getSizeRemaining() > 0) { nextOp = brr.get_uint8_t(); @@ -1365,7 +1365,7 @@ class BtcUtils uint32_t diffBits = READ_UINT32_LE(diffBitsBinary); int nShift = (diffBits >> 24) & 0xff; double dDiff = (double)0x0000ffff / (double)(diffBits & 0x00ffffff); - + while (nShift < 29) { dDiff *= 256.0; @@ -1384,7 +1384,7 @@ class BtcUtils // blk0001.dat to blocks/blk00000.dat static std::string getBlkFilename(std::string dir, uint32_t fblkNum) { - /// Update: It's been enough time since the hardfork that just about + /// Update: It's been enough time since the hardfork that just about // everyone must've upgraded to 0.8+ by now... remove pre-0.8 // compatibility. char* fname = new char[1024]; @@ -1423,7 +1423,7 @@ class BtcUtils case OP_14 : return "OP_14"; case OP_15 : return "OP_15"; case OP_16 : return "OP_16"; - + // control case OP_NOP : return "OP_NOP"; case OP_VER : return "OP_VER"; @@ -1435,7 +1435,7 @@ class BtcUtils case OP_ENDIF : return "OP_ENDIF"; case OP_VERIFY : return "OP_VERIFY"; case OP_RETURN : return "OP_RETURN"; - + // stack ops case OP_TOALTSTACK : return "OP_TOALTSTACK"; case OP_FROMALTSTACK : return "OP_FROMALTSTACK"; @@ -1456,14 +1456,14 @@ class BtcUtils case OP_ROT : return "OP_ROT"; case OP_SWAP : return "OP_SWAP"; case OP_TUCK : return "OP_TUCK"; - + // splice ops case OP_CAT : return "OP_CAT"; case OP_SUBSTR : return "OP_SUBSTR"; case OP_LEFT : return "OP_LEFT"; case OP_RIGHT : return "OP_RIGHT"; case OP_SIZE : return "OP_SIZE"; - + // bit logic case OP_INVERT : return "OP_INVERT"; case OP_AND : return "OP_AND"; @@ -1473,7 +1473,7 @@ class BtcUtils case OP_EQUALVERIFY : return "OP_EQUALVERIFY"; case OP_RESERVED1 : return "OP_RESERVED1"; case OP_RESERVED2 : return "OP_RESERVED2"; - + // numeric case OP_1ADD : return "OP_1ADD"; case OP_1SUB : return "OP_1SUB"; @@ -1502,7 +1502,7 @@ class BtcUtils case OP_MIN : return "OP_MIN"; case OP_MAX : return "OP_MAX"; case OP_WITHIN : return "OP_WITHIN"; - + // crypto case OP_RIPEMD160 : return "OP_RIPEMD160"; case OP_SHA1 : return "OP_SHA1"; @@ -1514,7 +1514,7 @@ class BtcUtils case OP_CHECKSIGVERIFY : return "OP_CHECKSIGVERIFY"; case OP_CHECKMULTISIG : return "OP_CHECKMULTISIG"; case OP_CHECKMULTISIGVERIFY : return "OP_CHECKMULTISIGVERIFY"; - + // expanson case OP_NOP1 : return "OP_NOP1"; case OP_NOP2 : return "OP_NOP2"; @@ -1526,19 +1526,19 @@ class BtcUtils case OP_NOP8 : return "OP_NOP8"; case OP_NOP9 : return "OP_NOP9"; case OP_NOP10 : return "OP_NOP10"; - - - + + + // template matching params case OP_PUBKEYHASH : return "OP_PUBKEYHASH"; case OP_PUBKEY : return "OP_PUBKEY"; - + case OP_INVALIDOPCODE : return "OP_INVALIDOPCODE"; default: return "OP_UNKNOWN"; } } - + static std::vector convertScriptToOpStrings(BinaryData const & script) { std::list opList; @@ -1592,7 +1592,7 @@ class BtcUtils opList.push_back(getOpCodeName((OPCODETYPE)nextOp)); i++; } - + } if(error) @@ -1612,7 +1612,7 @@ class BtcUtils } return vectOut; } - + static void pprintScript(BinaryData const & script) { std::vector oplist = convertScriptToOpStrings(script); @@ -1630,12 +1630,12 @@ class BtcUtils return false; srcsz = std::min((uint32_t)srcsz, nbytes); - + BinaryData temp((size_t)srcsz); std::ifstream is(src.c_str(), std::ios::in | std::ios::binary); is.read((char*)temp.getPtr(), srcsz); is.close(); - + std::ofstream os(dst.c_str(), std::ios::out | std::ios::binary); os.write((char*)temp.getPtr(), srcsz); os.close(); @@ -1692,7 +1692,7 @@ class BtcUtils static bool verifyProofOfWork(BinaryDataRef bh80, BinaryDataRef bhrHash) { - // This is only approximate. I can put in an exact verifier once + // This is only approximate. I can put in an exact verifier once // I figure out big integers better in C++, or another way to do // the calculation. I just want to make sure this isn't a completely // bogus proof of work. @@ -1709,7 +1709,7 @@ class BtcUtils return true; } */ - + static BinaryData scrAddrToBase58(const BinaryData& scrAddr) { /*** @@ -1732,12 +1732,12 @@ class BtcUtils auto&& scriptNhash = base58_decode(b58Addr); //should be at least 4 bytes checksum + 1 version byte - if (scriptNhash.getSize() <= 5) + if (scriptNhash.getSize() <= 5) throw std::range_error("invalid b58 decoded address length"); //split last 4 bytes auto len = scriptNhash.getSize(); - auto scriptRef = + auto scriptRef = scriptNhash.getSliceRef(0, len - 4); auto checksumRef = @@ -1758,7 +1758,7 @@ class BtcUtils BinaryData b58_str(size); if (!btc_base58_encode( b58_str.getCharPtr(), &size, - payload.getPtr(), payload.getSize()) || + payload.getPtr(), payload.getSize()) || size > b58_str.getSize()) { throw std::runtime_error("failed to encode b58 string"); @@ -1810,7 +1810,7 @@ class BtcUtils int zeroCount = 32 - len; while (zeroCount-- > 0) output.put_uint8_t(0); - + output.put_BinaryData(data); } }; @@ -2036,5 +2036,5 @@ class BtcUtils static BinaryData segWitAddressToScrAddr(const BinaryData& swAddr); static int get_varint_len(const int64_t& value); }; - + #endif diff --git a/cppForSwig/log.h b/cppForSwig/log.h index f8c53aaf4..bc02812f7 100644 --- a/cppForSwig/log.h +++ b/cppForSwig/log.h @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -86,7 +87,6 @@ #define FLUSHLOG() Log::FlushStreams() #define CLEANUPLOG() Log::CleanUp() -#define LOGTIMEBUFLEN 30 #define MAX_LOG_FILE_SIZE (500*1024) inline std::string NowTime(); @@ -211,15 +211,15 @@ class DualStream : public LogStream class NullStream : public LogStream { public: - LogStream& operator<<(const char * str) { return *this; } - LogStream& operator<<(std::string const & str) { return *this; } - LogStream& operator<<(int i) { return *this; } - LogStream& operator<<(unsigned int i) { return *this; } - LogStream& operator<<(unsigned long long int i) { return *this; } - LogStream& operator<<(float f) { return *this; } - LogStream& operator<<(double d) { return *this; } + LogStream& operator<<(const char*) { return *this; } + LogStream& operator<<(std::string const&) { return *this; } + LogStream& operator<<(int) { return *this; } + LogStream& operator<<(unsigned int) { return *this; } + LogStream& operator<<(unsigned long long int) { return *this; } + LogStream& operator<<(float) { return *this; } + LogStream& operator<<(double) { return *this; } #if !defined(_MSC_VER) && !defined(__MINGW32__) && defined(__LP64__) - LogStream& operator<<(size_t i) { return *this; } + LogStream& operator<<(size_t) { return *this; } #endif void FlushStreams(void) {} @@ -384,19 +384,17 @@ inline std::string NowTime() timeDur -= std::chrono::duration_cast(timeDur); unsigned int ms = static_cast(timeDur / std::chrono::milliseconds(1)); - // Print time. + // Print time. snprintf() causes warnings under clang and requires weird + // workarounds to stop them. Just use stringstream, which is cleaner. time_t curTimeTT = std::chrono::system_clock::to_time_t(curTime); tm* tStruct = localtime(&curTimeTT); - std::string timeStr = "%04i-%02i-%02i - %02i:%02i:%02i.%03i"; - char result[LOGTIMEBUFLEN] = {0}; - snprintf(result, sizeof(result), timeStr.c_str(), tStruct->tm_year + 1900, \ - tStruct->tm_mon + 1, \ - tStruct->tm_mday, \ - tStruct->tm_hour, \ - tStruct->tm_min, \ - tStruct->tm_sec, \ - ms); - return result; + auto&& oss = std::ostringstream(); + oss << std::setw(4) << tStruct->tm_year + 1900 << "-" << std::setfill('0') + << std::setw(2) << tStruct->tm_mon + 1 << "-" << tStruct->tm_mday + << " - " << tStruct->tm_hour << ":" << tStruct->tm_min << ":" + << tStruct->tm_sec << "." << std::setw(3) << ms; + + return oss.str(); } #endif //__LOG_H__