From 84809e42c9b1ea01271a887fb100f94d058b3d9a 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 | 2 +- cppForSwig/log.h | 38 ++++++++++++++++++-------------------- 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/cppForSwig/AsyncClient.h b/cppForSwig/AsyncClient.h index 5ca26ec20..9b04a5a56 100644 --- a/cppForSwig/AsyncClient.h +++ b/cppForSwig/AsyncClient.h @@ -36,7 +36,8 @@ class ClientMessageError : public runtime_error }; /////////////////////////////////////////////////////////////////////////////// -template class ReturnMessage +template +class ReturnMessage { private: U value_; @@ -108,9 +109,9 @@ namespace AsyncClient class LedgerDelegate { private: + shared_ptr sock_; string delegateID_; string bdvID_; - shared_ptr sock_; public: LedgerDelegate(void) {} @@ -130,17 +131,17 @@ namespace AsyncClient friend class ::WalletContainer; private: + const shared_ptr sock_; const string bdvID_; const string walletID_; const BinaryData scrAddr_; + const int index_; BinaryData addrHash_; - const shared_ptr sock_; const uint64_t fullBalance_; const uint64_t spendableBalance_; const uint64_t unconfirmedBalance_; const uint32_t count_; - const int index_; string comment_; @@ -181,9 +182,9 @@ namespace AsyncClient friend class ScrAddrObj; protected: + const shared_ptr sock_; const string walletID_; const string bdvID_; - const shared_ptr sock_; public: BtcWallet(const BlockDataViewer&, const string&); @@ -397,9 +398,9 @@ struct CallbackReturn_String : public CallbackReturn_WebSocket struct CallbackReturn_LedgerDelegate : public CallbackReturn_WebSocket { private: - function)> userCallbackLambda_; shared_ptr sockPtr_; const string& bdvID_; + function)> userCallbackLambda_; public: CallbackReturn_LedgerDelegate( @@ -416,9 +417,9 @@ struct CallbackReturn_LedgerDelegate : public CallbackReturn_WebSocket struct CallbackReturn_Tx : public CallbackReturn_WebSocket { private: - function)> userCallbackLambda_; shared_ptr cache_; BinaryData txHash_; + function)> userCallbackLambda_; public: CallbackReturn_Tx(shared_ptr cache, @@ -434,10 +435,10 @@ struct CallbackReturn_Tx : public CallbackReturn_WebSocket struct CallbackReturn_RawHeader : public CallbackReturn_WebSocket { private: - function)> userCallbackLambda_; shared_ptr cache_; BinaryData txHash_; unsigned height_; + function)> userCallbackLambda_; public: CallbackReturn_RawHeader( @@ -653,8 +654,8 @@ struct CallbackReturn_Bool : public CallbackReturn_WebSocket struct CallbackReturn_BlockHeader : public CallbackReturn_WebSocket { private: - function)> userCallbackLambda_; const unsigned height_; + function)> userCallbackLambda_; public: CallbackReturn_BlockHeader(unsigned height, diff --git a/cppForSwig/BinaryData.h b/cppForSwig/BinaryData.h index 12440232c..779777c0e 100644 --- a/cppForSwig/BinaryData.h +++ b/cppForSwig/BinaryData.h @@ -945,7 +945,7 @@ class BinaryReader ///////////////////////////////////////////////////////////////////////////// - uint8_t get_uint8_t(ENDIAN e=LE) + uint8_t get_uint8_t() { uint8_t outVal = bdStr_[pos_]; pos_ += 1; @@ -1127,7 +1127,7 @@ class BinaryRefReader ///////////////////////////////////////////////////////////////////////////// - uint8_t get_uint8_t(ENDIAN e=LE) + uint8_t get_uint8_t() { if (getSizeRemaining() < 1) { @@ -1436,7 +1436,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 2a751bde0..240c52731 100644 --- a/cppForSwig/BtcUtils.h +++ b/cppForSwig/BtcUtils.h @@ -1843,7 +1843,7 @@ class BtcUtils CryptoPP::Integer exponent = CryptoPP::Integer::One(); CryptoPP::Integer five_eight(58); CryptoPP::Integer value = CryptoPP::Integer::Zero(); - for (int i = b58.getSize() - 1; i >= offset; i--) + for (int i = (int)b58.getSize() - 1; i >= offset; i--) { auto b58Iter = base58Vals_.find(ptr[i]); if (b58Iter == base58Vals_.end()) 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__