Skip to content

Commit

Permalink
Fix header warnings (Part 1)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
droark committed Dec 22, 2018
1 parent f2c1e37 commit 84809e4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
19 changes: 10 additions & 9 deletions cppForSwig/AsyncClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class ClientMessageError : public runtime_error
};

///////////////////////////////////////////////////////////////////////////////
template<class U> class ReturnMessage
template<class U>
class ReturnMessage
{
private:
U value_;
Expand Down Expand Up @@ -108,9 +109,9 @@ namespace AsyncClient
class LedgerDelegate
{
private:
shared_ptr<SocketPrototype> sock_;
string delegateID_;
string bdvID_;
shared_ptr<SocketPrototype> sock_;

public:
LedgerDelegate(void) {}
Expand All @@ -130,17 +131,17 @@ namespace AsyncClient
friend class ::WalletContainer;

private:
const shared_ptr<SocketPrototype> sock_;
const string bdvID_;
const string walletID_;
const BinaryData scrAddr_;
const int index_;
BinaryData addrHash_;
const shared_ptr<SocketPrototype> sock_;

const uint64_t fullBalance_;
const uint64_t spendableBalance_;
const uint64_t unconfirmedBalance_;
const uint32_t count_;
const int index_;

string comment_;

Expand Down Expand Up @@ -181,9 +182,9 @@ namespace AsyncClient
friend class ScrAddrObj;

protected:
const shared_ptr<SocketPrototype> sock_;
const string walletID_;
const string bdvID_;
const shared_ptr<SocketPrototype> sock_;

public:
BtcWallet(const BlockDataViewer&, const string&);
Expand Down Expand Up @@ -397,9 +398,9 @@ struct CallbackReturn_String : public CallbackReturn_WebSocket
struct CallbackReturn_LedgerDelegate : public CallbackReturn_WebSocket
{
private:
function<void(ReturnMessage<AsyncClient::LedgerDelegate>)> userCallbackLambda_;
shared_ptr<SocketPrototype> sockPtr_;
const string& bdvID_;
function<void(ReturnMessage<AsyncClient::LedgerDelegate>)> userCallbackLambda_;

public:
CallbackReturn_LedgerDelegate(
Expand All @@ -416,9 +417,9 @@ struct CallbackReturn_LedgerDelegate : public CallbackReturn_WebSocket
struct CallbackReturn_Tx : public CallbackReturn_WebSocket
{
private:
function<void(ReturnMessage<Tx>)> userCallbackLambda_;
shared_ptr<ClientCache> cache_;
BinaryData txHash_;
function<void(ReturnMessage<Tx>)> userCallbackLambda_;

public:
CallbackReturn_Tx(shared_ptr<ClientCache> cache,
Expand All @@ -434,10 +435,10 @@ struct CallbackReturn_Tx : public CallbackReturn_WebSocket
struct CallbackReturn_RawHeader : public CallbackReturn_WebSocket
{
private:
function<void(ReturnMessage<BinaryData>)> userCallbackLambda_;
shared_ptr<ClientCache> cache_;
BinaryData txHash_;
unsigned height_;
function<void(ReturnMessage<BinaryData>)> userCallbackLambda_;

public:
CallbackReturn_RawHeader(
Expand Down Expand Up @@ -653,8 +654,8 @@ struct CallbackReturn_Bool : public CallbackReturn_WebSocket
struct CallbackReturn_BlockHeader : public CallbackReturn_WebSocket
{
private:
function<void(ReturnMessage<ClientClasses::BlockHeader>)> userCallbackLambda_;
const unsigned height_;
function<void(ReturnMessage<ClientClasses::BlockHeader>)> userCallbackLambda_;

public:
CallbackReturn_BlockHeader(unsigned height,
Expand Down
6 changes: 3 additions & 3 deletions cppForSwig/BinaryData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1127,7 +1127,7 @@ class BinaryRefReader


/////////////////////////////////////////////////////////////////////////////
uint8_t get_uint8_t(ENDIAN e=LE)
uint8_t get_uint8_t()
{
if (getSizeRemaining() < 1)
{
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cppForSwig/BtcUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
38 changes: 18 additions & 20 deletions cppForSwig/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <string>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <thread>
#include <mutex>
Expand All @@ -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();
Expand Down Expand Up @@ -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) {}
Expand Down Expand Up @@ -384,19 +384,17 @@ inline std::string NowTime()
timeDur -= std::chrono::duration_cast<std::chrono::seconds>(timeDur);
unsigned int ms = static_cast<unsigned>(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__

0 comments on commit 84809e4

Please sign in to comment.