build: fix all warnings, treat warnings as errors

pull/2/head
xiphon 4 years ago
parent eb7fae92ef
commit 98abdaa5d5

@ -337,6 +337,8 @@ if(APPLE)
endif() endif()
# warnings # warnings
add_c_flag_if_supported(-Werror C_SECURITY_FLAGS)
add_cxx_flag_if_supported(-Werror CXX_SECURITY_FLAGS)
add_c_flag_if_supported(-Wformat C_SECURITY_FLAGS) add_c_flag_if_supported(-Wformat C_SECURITY_FLAGS)
add_cxx_flag_if_supported(-Wformat CXX_SECURITY_FLAGS) add_cxx_flag_if_supported(-Wformat CXX_SECURITY_FLAGS)
add_c_flag_if_supported(-Wformat-security C_SECURITY_FLAGS) add_c_flag_if_supported(-Wformat-security C_SECURITY_FLAGS)

@ -176,8 +176,8 @@ android {
QMAKE_CXXFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -Wformat -Wformat-security QMAKE_CXXFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -Werror -Wformat -Wformat-security
QMAKE_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -Wformat -Wformat-security QMAKE_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -Werror -Wformat -Wformat-security
ios { ios {
message("Host is IOS") message("Host is IOS")

@ -27,6 +27,7 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "DaemonManager.h" #include "DaemonManager.h"
#include <QElapsedTimer>
#include <QFile> #include <QFile>
#include <QThread> #include <QThread>
#include <QFileInfo> #include <QFileInfo>
@ -36,7 +37,6 @@
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
#include <QApplication> #include <QApplication>
#include <QProcess> #include <QProcess>
#include <QTime>
#include <QStorageInfo> #include <QStorageInfo>
#include <QVariantMap> #include <QVariantMap>
#include <QVariant> #include <QVariant>
@ -173,8 +173,8 @@ bool DaemonManager::stop(NetworkType::Type nettype)
bool DaemonManager::startWatcher(NetworkType::Type nettype) const bool DaemonManager::startWatcher(NetworkType::Type nettype) const
{ {
// Check if daemon is started every 2 seconds // Check if daemon is started every 2 seconds
QTime timer; QElapsedTimer timer;
timer.restart(); timer.start();
while(true && !m_app_exit && timer.elapsed() / 1000 < DAEMON_START_TIMEOUT_SECONDS ) { while(true && !m_app_exit && timer.elapsed() / 1000 < DAEMON_START_TIMEOUT_SECONDS ) {
QThread::sleep(2); QThread::sleep(2);
if(!running(nettype)) { if(!running(nettype)) {

@ -32,7 +32,6 @@
AddressBook::AddressBook(Monero::AddressBook *abImpl,QObject *parent) AddressBook::AddressBook(Monero::AddressBook *abImpl,QObject *parent)
: QObject(parent), m_addressBookImpl(abImpl) : QObject(parent), m_addressBookImpl(abImpl)
{ {
qDebug(__FUNCTION__);
getAll(); getAll();
} }
@ -48,8 +47,6 @@ int AddressBook::errorCode() const
void AddressBook::getAll() void AddressBook::getAll()
{ {
qDebug(__FUNCTION__);
emit refreshStarted(); emit refreshStarted();
{ {

@ -36,7 +36,7 @@
#include <QDateTime> #include <QDateTime>
namespace Monero { namespace Monero {
class AddressBook; struct AddressBook;
} }
class AddressBookRow; class AddressBookRow;

@ -32,14 +32,11 @@
Subaddress::Subaddress(Monero::Subaddress *subaddressImpl, QObject *parent) Subaddress::Subaddress(Monero::Subaddress *subaddressImpl, QObject *parent)
: QObject(parent), m_subaddressImpl(subaddressImpl) : QObject(parent), m_subaddressImpl(subaddressImpl)
{ {
qDebug(__FUNCTION__);
getAll(); getAll();
} }
void Subaddress::getAll() const void Subaddress::getAll() const
{ {
qDebug(__FUNCTION__);
emit refreshStarted(); emit refreshStarted();
{ {

@ -32,14 +32,11 @@
SubaddressAccount::SubaddressAccount(Monero::SubaddressAccount *subaddressAccountImpl, QObject *parent) SubaddressAccount::SubaddressAccount(Monero::SubaddressAccount *subaddressAccountImpl, QObject *parent)
: QObject(parent), m_subaddressAccountImpl(subaddressAccountImpl) : QObject(parent), m_subaddressAccountImpl(subaddressAccountImpl)
{ {
qDebug(__FUNCTION__);
getAll(); getAll();
} }
void SubaddressAccount::getAll() const void SubaddressAccount::getAll() const
{ {
qDebug(__FUNCTION__);
emit refreshStarted(); emit refreshStarted();
{ {

@ -37,7 +37,7 @@
#include <QDateTime> #include <QDateTime>
namespace Monero { namespace Monero {
class TransactionHistory; struct TransactionHistory;
} }
class TransactionInfo; class TransactionInfo;

@ -68,38 +68,38 @@ public:
} }
virtual void moneySpent(const std::string &txId, uint64_t amount) virtual void moneySpent(const std::string &txId, uint64_t amount) override
{ {
qDebug() << __FUNCTION__; qDebug() << __FUNCTION__;
emit m_wallet->moneySpent(QString::fromStdString(txId), amount); emit m_wallet->moneySpent(QString::fromStdString(txId), amount);
} }
virtual void moneyReceived(const std::string &txId, uint64_t amount) virtual void moneyReceived(const std::string &txId, uint64_t amount) override
{ {
qDebug() << __FUNCTION__; qDebug() << __FUNCTION__;
emit m_wallet->moneyReceived(QString::fromStdString(txId), amount); emit m_wallet->moneyReceived(QString::fromStdString(txId), amount);
} }
virtual void unconfirmedMoneyReceived(const std::string &txId, uint64_t amount) virtual void unconfirmedMoneyReceived(const std::string &txId, uint64_t amount) override
{ {
qDebug() << __FUNCTION__; qDebug() << __FUNCTION__;
emit m_wallet->unconfirmedMoneyReceived(QString::fromStdString(txId), amount); emit m_wallet->unconfirmedMoneyReceived(QString::fromStdString(txId), amount);
} }
virtual void newBlock(uint64_t height) virtual void newBlock(uint64_t height) override
{ {
// qDebug() << __FUNCTION__; // qDebug() << __FUNCTION__;
emit m_wallet->newBlock(height, m_wallet->daemonBlockChainTargetHeight()); emit m_wallet->newBlock(height, m_wallet->daemonBlockChainTargetHeight());
} }
virtual void updated() virtual void updated() override
{ {
emit m_wallet->updated(); emit m_wallet->updated();
} }
// called when wallet refreshed by background thread or explicitly // called when wallet refreshed by background thread or explicitly
virtual void refreshed() virtual void refreshed() override
{ {
qDebug() << __FUNCTION__; qDebug() << __FUNCTION__;
emit m_wallet->refreshed(); emit m_wallet->refreshed();
@ -1028,9 +1028,9 @@ Wallet::Wallet(Monero::Wallet *w, QObject *parent)
m_walletImpl->setListener(m_walletListener); m_walletImpl->setListener(m_walletListener);
m_currentSubaddressAccount = getCacheAttribute(ATTRIBUTE_SUBADDRESS_ACCOUNT).toUInt(); m_currentSubaddressAccount = getCacheAttribute(ATTRIBUTE_SUBADDRESS_ACCOUNT).toUInt();
// start cache timers // start cache timers
m_connectionStatusTime.restart(); m_connectionStatusTime.start();
m_daemonBlockChainHeightTime.restart(); m_daemonBlockChainHeightTime.start();
m_daemonBlockChainTargetHeightTime.restart(); m_daemonBlockChainTargetHeightTime.start();
m_initialized = false; m_initialized = false;
m_connectionStatusRunning = false; m_connectionStatusRunning = false;
m_daemonUsername = ""; m_daemonUsername = "";

@ -29,8 +29,8 @@
#ifndef WALLET_H #ifndef WALLET_H
#define WALLET_H #define WALLET_H
#include <QElapsedTimer>
#include <QObject> #include <QObject>
#include <QTime>
#include <QMutex> #include <QMutex>
#include <QList> #include <QList>
#include <QJSValue> #include <QJSValue>
@ -43,7 +43,7 @@
#include "NetworkType.h" #include "NetworkType.h"
namespace Monero { namespace Monero {
class Wallet; // forward declaration struct Wallet; // forward declaration
} }
@ -406,15 +406,15 @@ private:
QString m_paymentId; QString m_paymentId;
AddressBook * m_addressBook; AddressBook * m_addressBook;
mutable AddressBookModel * m_addressBookModel; mutable AddressBookModel * m_addressBookModel;
mutable QTime m_daemonBlockChainHeightTime; mutable QElapsedTimer m_daemonBlockChainHeightTime;
mutable quint64 m_daemonBlockChainHeight; mutable quint64 m_daemonBlockChainHeight;
int m_daemonBlockChainHeightTtl; int m_daemonBlockChainHeightTtl;
mutable QTime m_daemonBlockChainTargetHeightTime; mutable QElapsedTimer m_daemonBlockChainTargetHeightTime;
mutable quint64 m_daemonBlockChainTargetHeight; mutable quint64 m_daemonBlockChainTargetHeight;
int m_daemonBlockChainTargetHeightTtl; int m_daemonBlockChainTargetHeightTtl;
mutable ConnectionStatus m_connectionStatus; mutable ConnectionStatus m_connectionStatus;
int m_connectionStatusTtl; int m_connectionStatusTtl;
mutable QTime m_connectionStatusTime; mutable QElapsedTimer m_connectionStatusTime;
bool m_disconnected; bool m_disconnected;
mutable bool m_initialized; mutable bool m_initialized;
uint32_t m_currentSubaddressAccount; uint32_t m_currentSubaddressAccount;

@ -42,7 +42,7 @@
class Wallet; class Wallet;
namespace Monero { namespace Monero {
class WalletManager; struct WalletManager;
} }
class WalletManager : public QObject class WalletManager : public QObject

@ -269,7 +269,7 @@ int main(int argc, char *argv[])
// screen settings // screen settings
// Mobile is designed on 128dpi // Mobile is designed on 128dpi
qreal ref_dpi = 128; qreal ref_dpi = 128;
QRect geo = QApplication::desktop()->availableGeometry(); QRect geo = QGuiApplication::primaryScreen()->availableGeometry();
QRect rect = QGuiApplication::primaryScreen()->geometry(); QRect rect = QGuiApplication::primaryScreen()->geometry();
qreal dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch(); qreal dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch();
qreal physicalDpi = QGuiApplication::primaryScreen()->physicalDotsPerInch(); qreal physicalDpi = QGuiApplication::primaryScreen()->physicalDotsPerInch();

@ -35,18 +35,15 @@
AddressBookModel::AddressBookModel(QObject *parent, AddressBook *addressBook) AddressBookModel::AddressBookModel(QObject *parent, AddressBook *addressBook)
: QAbstractListModel(parent) , m_addressBook(addressBook) : QAbstractListModel(parent) , m_addressBook(addressBook)
{ {
qDebug(__FUNCTION__);
connect(m_addressBook,SIGNAL(refreshStarted()),this,SLOT(startReset())); connect(m_addressBook,SIGNAL(refreshStarted()),this,SLOT(startReset()));
connect(m_addressBook,SIGNAL(refreshFinished()),this,SLOT(endReset())); connect(m_addressBook,SIGNAL(refreshFinished()),this,SLOT(endReset()));
} }
void AddressBookModel::startReset(){ void AddressBookModel::startReset(){
qDebug(__FUNCTION__);
beginResetModel(); beginResetModel();
} }
void AddressBookModel::endReset(){ void AddressBookModel::endReset(){
qDebug(__FUNCTION__);
endResetModel(); endResetModel();
} }

@ -35,17 +35,14 @@
SubaddressAccountModel::SubaddressAccountModel(QObject *parent, SubaddressAccount *subaddressAccount) SubaddressAccountModel::SubaddressAccountModel(QObject *parent, SubaddressAccount *subaddressAccount)
: QAbstractListModel(parent), m_subaddressAccount(subaddressAccount) : QAbstractListModel(parent), m_subaddressAccount(subaddressAccount)
{ {
qDebug(__FUNCTION__);
connect(m_subaddressAccount,SIGNAL(refreshStarted()),this,SLOT(startReset())); connect(m_subaddressAccount,SIGNAL(refreshStarted()),this,SLOT(startReset()));
connect(m_subaddressAccount,SIGNAL(refreshFinished()),this,SLOT(endReset())); connect(m_subaddressAccount,SIGNAL(refreshFinished()),this,SLOT(endReset()));
} }
void SubaddressAccountModel::startReset(){ void SubaddressAccountModel::startReset(){
qDebug("SubaddressAccountModel::startReset");
beginResetModel(); beginResetModel();
} }
void SubaddressAccountModel::endReset(){ void SubaddressAccountModel::endReset(){
qDebug("SubaddressAccountModel::endReset");
endResetModel(); endResetModel();
} }

@ -35,18 +35,15 @@
SubaddressModel::SubaddressModel(QObject *parent, Subaddress *subaddress) SubaddressModel::SubaddressModel(QObject *parent, Subaddress *subaddress)
: QAbstractListModel(parent), m_subaddress(subaddress) : QAbstractListModel(parent), m_subaddress(subaddress)
{ {
qDebug(__FUNCTION__);
connect(m_subaddress,SIGNAL(refreshStarted()),this,SLOT(startReset())); connect(m_subaddress,SIGNAL(refreshStarted()),this,SLOT(startReset()));
connect(m_subaddress,SIGNAL(refreshFinished()),this,SLOT(endReset())); connect(m_subaddress,SIGNAL(refreshFinished()),this,SLOT(endReset()));
} }
void SubaddressModel::startReset(){ void SubaddressModel::startReset(){
qDebug(__FUNCTION__);
beginResetModel(); beginResetModel();
} }
void SubaddressModel::endReset(){ void SubaddressModel::endReset(){
qDebug(__FUNCTION__);
endResetModel(); endResetModel();
} }

@ -38,7 +38,7 @@ QPair<bool, QFuture<void>> FutureScheduler::run(std::function<void()> function)
}); });
} }
QPair<bool, QFuture<QJSValueList>> FutureScheduler::run(std::function<QJSValueList() noexcept> function, const QJSValue &callback) QPair<bool, QFuture<QJSValueList>> FutureScheduler::run(std::function<QJSValueList()> function, const QJSValue &callback)
{ {
if (!callback.isCallable()) if (!callback.isCallable())
{ {

@ -22,20 +22,12 @@ public:
void shutdownWaitForFinished() noexcept; void shutdownWaitForFinished() noexcept;
QPair<bool, QFuture<void>> run(std::function<void()> function) noexcept; QPair<bool, QFuture<void>> run(std::function<void()> function) noexcept;
QPair<bool, QFuture<QJSValueList>> run(std::function<QJSValueList() noexcept> function, const QJSValue &callback); QPair<bool, QFuture<QJSValueList>> run(std::function<QJSValueList()> function, const QJSValue &callback);
private: private:
bool add() noexcept; bool add() noexcept;
void done() noexcept; void done() noexcept;
template<typename T>
QFutureWatcher<T> *newWatcher()
{
QFutureWatcher<T> *watcher = new QFutureWatcher<T>();
return watcher;
}
template<typename T> template<typename T>
QPair<bool, QFuture<T>> execute(std::function<QFuture<T>(QFutureWatcher<T> *)> makeFuture) noexcept QPair<bool, QFuture<T>> execute(std::function<QFuture<T>(QFutureWatcher<T> *)> makeFuture) noexcept
{ {
@ -43,8 +35,8 @@ private:
{ {
try try
{ {
auto *watcher = newWatcher<T>(); auto *watcher = new QFutureWatcher<T>();
connect(watcher, &QFutureWatcher<T>::finished, [this, watcher] { connect(watcher, &QFutureWatcher<T>::finished, [watcher] {
watcher->deleteLater(); watcher->deleteLater();
}); });
watcher->setFuture(makeFuture(watcher)); watcher->setFuture(makeFuture(watcher));

@ -43,8 +43,8 @@
#include "KeysFiles.h" #include "KeysFiles.h"
WalletKeysFiles::WalletKeysFiles(const qint64 &modified, const qint64 &created, const QString &path, const quint8 &networkType, const QString &address) WalletKeysFiles::WalletKeysFiles(const qint64 &modified, const QString &path, const quint8 &networkType, const QString &address)
: m_modified(modified), m_created(created), m_path(path), m_networkType(networkType), m_address(address) : m_modified(modified), m_path(path), m_networkType(networkType), m_address(address)
{ {
} }
@ -58,11 +58,6 @@ QString WalletKeysFiles::address() const
return m_address; return m_address;
} }
qint64 WalletKeysFiles::created() const
{
return m_created;
}
QString WalletKeysFiles::path() const QString WalletKeysFiles::path() const
{ {
return m_path; return m_path;
@ -134,10 +129,8 @@ void WalletKeysFilesModel::findWallets(const QString &moneroAccountsDir)
const QFileInfo info(wallet); const QFileInfo info(wallet);
const QDateTime modifiedAt = info.lastModified(); const QDateTime modifiedAt = info.lastModified();
const QDateTime createdAt = info.created(); // @TODO: QFileInfo::birthTime() >= Qt 5.10
this->addWalletKeysFile(WalletKeysFiles(modifiedAt.toSecsSinceEpoch(), this->addWalletKeysFile(WalletKeysFiles(modifiedAt.toSecsSinceEpoch(),
createdAt.toSecsSinceEpoch(),
info.absoluteFilePath(), networkType, address)); info.absoluteFilePath(), networkType, address));
} }
} }
@ -167,8 +160,6 @@ QVariant WalletKeysFilesModel::data(const QModelIndex & index, int role) const {
return walletKeyFile.networkType(); return walletKeyFile.networkType();
else if (role == AddressRole) else if (role == AddressRole)
return walletKeyFile.address(); return walletKeyFile.address();
else if (role == CreatedRole)
return walletKeyFile.created();
return QVariant(); return QVariant();
} }
@ -178,6 +169,5 @@ QHash<int, QByteArray> WalletKeysFilesModel::roleNames() const {
roles[PathRole] = "path"; roles[PathRole] = "path";
roles[NetworkTypeRole] = "networktype"; roles[NetworkTypeRole] = "networktype";
roles[AddressRole] = "address"; roles[AddressRole] = "address";
roles[CreatedRole] = "created";
return roles; return roles;
} }

@ -37,17 +37,15 @@
class WalletKeysFiles class WalletKeysFiles
{ {
public: public:
WalletKeysFiles(const qint64 &modified, const qint64 &created, const QString &path, const quint8 &networkType, const QString &address); WalletKeysFiles(const qint64 &modified, const QString &path, const quint8 &networkType, const QString &address);
qint64 modified() const; qint64 modified() const;
qint64 created() const;
QString path() const; QString path() const;
quint8 networkType() const; quint8 networkType() const;
QString address() const; QString address() const;
private: private:
qint64 m_modified; qint64 m_modified;
qint64 m_created;
QString m_path; QString m_path;
quint8 m_networkType; quint8 m_networkType;
QString m_address; QString m_address;
@ -61,8 +59,7 @@ public:
ModifiedRole = Qt::UserRole + 1, ModifiedRole = Qt::UserRole + 1,
PathRole, PathRole,
NetworkTypeRole, NetworkTypeRole,
AddressRole, AddressRole
CreatedRole
}; };
WalletKeysFilesModel(WalletManager *walletManager, QObject *parent = 0); WalletKeysFilesModel(WalletManager *walletManager, QObject *parent = 0);

@ -884,7 +884,7 @@ void CreateArrays(NodeSPtr Root, StringIntSet_t & StrSet, StringOfInts & ChildAd
if (x >= (1 << BITS_CHILD_MAP_INDEX)) if (x >= (1 << BITS_CHILD_MAP_INDEX))
{ {
char Tmp[20]; char Tmp[20];
snprintf(Tmp, sizeof Tmp, "%lu", x); snprintf(Tmp, sizeof Tmp, "%zu", x);
throw string("Not enough bits for child map index value of ") + Tmp + " for " + throw string("Not enough bits for child map index value of ") + Tmp + " for " +
Its->s + " (BITS_CHILD_MAP_INDEX too small)"; Its->s + " (BITS_CHILD_MAP_INDEX too small)";
} }
@ -1046,7 +1046,7 @@ static int OutputBinary(ostream *Out, const string & ChkFile, const string & Cha
Out->write((char *)WordEnds, NumWordEnd); Out->write((char *)WordEnds, NumWordEnd);
h(WordEnds, NumWordEnd); h(WordEnds, NumWordEnd);
OutputSize += NumWordEnd; OutputSize += NumWordEnd;
delete WordEnds; delete[] WordEnds;
StringIntSet_t::iterator Its; StringIntSet_t::iterator Its;
string Str; string Str;

@ -960,7 +960,7 @@ typedef struct
} SpatialMatchInfo_t; } SpatialMatchInfo_t;
/* Shift mapping, characters in pairs: first is shifted, second un-shifted. */ /* Shift mapping, characters in pairs: first is shifted, second un-shifted. */
static const uint8_t UK_Shift[] = "!1\"2$4%5&7(9)0*8:;<,>.?/@'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz^6_-{[|\\}]~#€4£3¬`"; static const uint8_t UK_Shift[] = "!1\"2$4%5&7(9)0*8:;<,>.?/@'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz^6_-{[|\\}]~#\x80""4\xA3""3\xAC`";
static const uint8_t US_Shift[] = "!1\"'#3$4%5&7(9)0*8:;<,>.?/@2AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz^6_-{[|\\}]~`"; static const uint8_t US_Shift[] = "!1\"'#3$4%5&7(9)0*8:;<,>.?/@2AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz^6_-{[|\\}]~`";